Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a category and the corresponding template parser for Liquid #680

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
"jscodeshift": "^0.11.0",
"json-stringify-safe": "^5.0.1",
"json-to-ast": "^2.1.0",
"liquidjs": "^10.0.0",
"lodash.isequal": "^4.5.0",
"luaparse": "^0.3.0",
"lucene": "^2.1.1",
Expand Down
6 changes: 6 additions & 0 deletions website/src/parsers/liquid/codeExample.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<h2>Introduction to Liquid</h2>
<p>
{% if username %}
{{ username | append: ", welcome to Liquid!" | capitalize }}
{% endif %}
</p>
7 changes: 7 additions & 0 deletions website/src/parsers/liquid/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import 'codemirror/mode/htmlmixed/htmlmixed';

export const id = 'liquid';
export const displayName = 'Liquid';
export const mimeTypes = ['text/html'];
export const fileExtension = 'liquid';
export const editorMode = 'htmlmixed';
69 changes: 69 additions & 0 deletions website/src/parsers/liquid/liquidjs-parser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import defaultParserInterface from '../utils/defaultParserInterface';
import pkg from 'liquidjs/package.json';

const ID = 'liquidjs';

const TokenNames = {
1: 'Number',
2: 'Literal',
4: 'Tag',
8: 'Output',
16: 'HTML',
32: 'Filter',
64: 'Hash',
128: 'PropertyAccess',
256: 'Word',
512: 'Range',
1024: 'Quoted',
2048: 'Operator',
};

export default {
...defaultParserInterface,

id: ID,
displayName: ID,
version: pkg.version,
homepage: pkg.homepage,
locationProps: new Set(['begin', 'end']),
typeProps: new Set(['kind']),

loadParser(callback) {
require(['liquidjs'], (module) => callback(new module.Liquid()));
},

parse(parser, code) {
return parser.parse(code);
},

opensByDefault(node, key) {
return key === 'token';
},

nodeToRange(node) {
if (typeof node.kind === 'number') {
return [node.begin, node.end];
}
if (node.token && typeof node.token.kind === 'number') {
return [node.token.begin, node.token.end];
}
},

getNodeName(node) {
if (node.kind) {
return `${TokenNames[node.kind]}Token`
}
if (node.token) {
const tokenKind = TokenNames[node.token.kind];
if (tokenKind === 'Tag') {
return `Tag(${node.name})`
}
return tokenKind
}
},

getDefaultOptions() {
return {};
},
_ignoredProperties: new Set(['liquid', 'impl', 'file', 'kind', 'input', 'trimLeft', 'trimRight']),
};
5 changes: 5 additions & 0 deletions website/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7175,6 +7175,11 @@ lines-and-columns@^1.1.6:
resolved "https://registry.yarnpkg.com/lines-and-columns/-/lines-and-columns-1.1.6.tgz#1c00c743b433cd0a4e80758f7b64a57440d9ff00"
integrity sha1-HADHQ7QzzQpOgHWPe2SldEDZ/wA=

liquidjs@^10.0.0:
version "10.0.0"
resolved "https://registry.yarnpkg.com/liquidjs/-/liquidjs-10.0.0.tgz#282579e9f90f4bfd92ef7d09ad4f5aac3ec9fd61"
integrity sha512-uY3fKqBSRmnat0wB5qWk0W5N5iT78OUhuIXNRiMfhYQ3p35al9mEWKQ68/Z+WD54V2upaxEM8nHaZ6o1B8WCMA==

load-json-file@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/load-json-file/-/load-json-file-2.0.0.tgz#7947e42149af80d696cbf797bcaabcfe1fe29ca8"
Expand Down