| Name | Type | Default | Description |
|---|---|---|---|
loadType |
string | ajax |
optional
Method of loading markfile |
Example
const parser = new markus.Parser();
await parser.parseMarkfile('mark.view');
> [{type="elementNode", element: 'app', props: {...}, presets: [...]}]
Members
-
Method of loading markfile.
Methods
-
Generates AST from presets based on type and depth properties of a preset.
Name Type Description presetsArray.<Preset> List presets
Returns:
Type Description Array AST presets Example
parser.generateTree([ {type: 'elementNode', depth: 0, element: 'app'}, {type: 'elementNode', depth: 1, element: 'text'}, {type: 'propNode', depth: 2, name: 'text', value=''} {type: 'valueNode', depth: 3, value='TEXT NODE'} ]) > {type: 'elementNode', depth: 0, element: 'app', presets: [{ type: 'elementNode', depth: 1, element: 'text', props: { text: 'TEXT NODE' }} }] } -
Retrieves an element property from a
@prop valueand$prop valuestructureName Type Description linestring line with marklang markup
Returns:
Type Description Array.<string> attr from markline. [attrType, attrNane, attrValue] Example
parser.getAttr("@prop on") > ['propNode', "prop", true] parser.getAttr("@func(on, 20, text)") > ['propNode', "attr", [true, 20, 'text']] -
Getes comment from markline
Name Type Description linestring line with marklang markup
Returns:
Type Description string Comment from markline Example
getComment('elm.tag // some comment') > // some comment -
Finds the depth of the entry element. Calculated by the number of tabs at the beginning of the line.
Name Type Description linestring line with marklang markup
Returns:
Type Description number depth Example
parser.getDepth("\t\t\t\t") > 4 -
Get element name
Name Type Description linestring line with marklang markup
Returns:
Type Description string element name from markline Example
parser.getElement("sprite.tag#id(prop=data)") > "sprite" -
Extracts the element id from the
#id_nameconstructionName Type Description linestring line with marklang markup
Returns:
Type Description string element id from markline Example
parser.getId("el.tag1#cat.tag2.tag3") > "cat" -
Finds all import requests in the file from the
import pathconstructionName Type Description dataArray.<string> lines array with marklang markup
Returns:
Type Description Array.<string> imports data Example
parser.getImports([ 'import resources.mark', 'app(w=1920, h=900)', ' import scenes.mark' ].join('\n')); > ['resources.mark', 'styles.mark'] -
Retrieves all element properties from the structure (prop = data, ...)
Name Type Description linestring line with marklang markup
Returns:
Type Description Object element attrs from markline Example
parser.getInlineAttrs("el(texture=cat.png, font= Bebas Neue, visible = off, some.point.x = .4)") > {texture: "cat.png", font="Bebas Neue", visible: false, some: {point: {x: .4}}} -
Extracts all element tags from .tag_name construction
Name Type Description linestring line with marklang markup
Returns:
Type Description Array.<string> element tags from markline Example
parser.getTags("el.tag1#id.tag2.tag3") > ["tag1", "tag2", "tag3"] -
Extract text value from the
| .+constructionName Type Description linestring line with marklang markup
Returns:
Type Description string element value from markline Example
parser.getValue("| SOME VALUE "); > "SOME VALUE " -
Loaded markfiles from array pathes
Name Type Description pathesArray.<string> Patches to markfiles
Returns:
Type Description Promise Example
await parser.imports(['./mark.view', './resources.mark']); > [{name: 'mark.view', path: './mark.view', data: '...'}, {...}] -
Parse markfile to AST presets
Name Type Description filepathstring file path to markfile
Returns:
Type Description Promise Return promise with ast presets Example
await parser.parseMarkfile(['./mark.view'); > [{type="elementNode", element: 'app', props: {...}, presets: [...]}] -
Parse marklang string to preset
Name Type Description linestring String with marklang markup
Returns:
Type Description Preset Example
parser.parsePreset(' text.tag#id(obj.visible = yes) | VALUE') > { type: 'elementNode', depth: 2 element: 'text', id: 'id', tags: ['tag'], props: {obj: {visible: true}}, value: 'VALUE' } parser.parsePreset(' | VALUE TEXT') > { depth: 2, type: 'valueNode', value: 'VALUE TEXT' } parser.parsePreset(' @prop .3324') > { depth: 1, type: 'propNode', typeAttr: 'prop', name: 'prop', value: 0.3324 } parser.parsePreset(' @move(10, 30)') > { depth: 1, type: 'propNode', typeAttr: 'method', name: 'move', args: [10, 30] } -
Parse marklang lines array to presets. Calls parser.parsePreset (line [i])
Name Type Description linesArray.<string> Strings with marklang markup
Returns:
Type Description Array.<Preset> -
Parse query selector to object
Name Type Description querystring Query selector in marklang markup
Returns:
Type Description Object Query selector in object Example
parser.parseQuery('element.tag.tag2#id'); > {element: 'element', tags: ['tag', 'tag2'], id: 'id'} -
Convert value from props with support js types
Name Type Description valuestring Returns:
Type Description any Parsed value Example
parser.parseValue('no'|'off'|'false'); > false parser.parseValue('yes'|'on'|'true'); > true parser.parseValue('.5'|'+34'|'-34'|'3.32432'); > Number parser.parseValue('anystring'); > String -
Removes comment from markline
Name Type Description linestring line with marklang markup
Returns:
Type Description string markline without comment Example
removeComment('elm.tag // some comment') > 'elm.tag'