@markuplint/ml-core
Advanced tools
Comparing version 1.0.0-alpha.13 to 1.0.0-alpha.14
import { MLMarkupLanguageParser } from '@markuplint/ml-ast'; | ||
import { MLMLSpec } from '@markuplint/ml-spec'; | ||
import { RuleConfigValue, VerifiedResult } from '@markuplint/ml-config'; | ||
@@ -12,3 +11,2 @@ import { Document } from './ml-dom'; | ||
private _ast; | ||
private _specs; | ||
private _document; | ||
@@ -18,3 +16,3 @@ private _ruleset; | ||
private _rules; | ||
constructor(parser: MLMarkupLanguageParser, sourceCode: string, specs: MLMLSpec, ruleset: Ruleset, rules: MLRule<RuleConfigValue, unknown>[], messenger: Messenger); | ||
constructor(parser: MLMarkupLanguageParser, sourceCode: string, ruleset: Ruleset, rules: MLRule<RuleConfigValue, unknown>[], messenger: Messenger); | ||
get document(): Document<RuleConfigValue, unknown>; | ||
@@ -21,0 +19,0 @@ verify(fix?: boolean): Promise<VerifiedResult[]>; |
@@ -39,13 +39,11 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var ml_spec_1 = require("@markuplint/ml-spec"); | ||
var ml_dom_1 = require("./ml-dom"); | ||
var MLCore = /** @class */ (function () { | ||
function MLCore(parser, sourceCode, specs, ruleset, rules, messenger) { | ||
function MLCore(parser, sourceCode, ruleset, rules, messenger) { | ||
this._parser = parser; | ||
this._sourceCode = sourceCode; | ||
this._specs = ml_spec_1.getSpecOM(specs); | ||
this._ruleset = ruleset; | ||
this._messenger = messenger; | ||
this._ast = this._parser.parse(this._sourceCode); | ||
this._document = new ml_dom_1.Document(this._ast, this._specs, this._ruleset); | ||
this._document = new ml_dom_1.Document(this._ast, this._ruleset); | ||
this._rules = rules; | ||
@@ -98,3 +96,3 @@ } | ||
this._ast = this._parser.parse(this._sourceCode); | ||
this._document = new ml_dom_1.Document(this._ast, this._specs, this._ruleset); | ||
this._document = new ml_dom_1.Document(this._ast, this._ruleset); | ||
}; | ||
@@ -104,7 +102,7 @@ MLCore.prototype.setCode = function (sourceCode) { | ||
this._ast = this._parser.parse(this._sourceCode); | ||
this._document = new ml_dom_1.Document(this._ast, this._specs, this._ruleset); | ||
this._document = new ml_dom_1.Document(this._ast, this._ruleset); | ||
}; | ||
MLCore.prototype.setRuleset = function (ruleset) { | ||
this._ruleset = ruleset; | ||
this._document = new ml_dom_1.Document(this._ast, this._specs, this._ruleset); | ||
this._document = new ml_dom_1.Document(this._ast, this._ruleset); | ||
}; | ||
@@ -111,0 +109,0 @@ return MLCore; |
import { AnonymousNode } from './types'; | ||
import { SpecOM } from '@markuplint/ml-spec'; | ||
import { MLASTDocument } from '@markuplint/ml-ast'; | ||
@@ -18,6 +17,2 @@ import { MLDOMComment, MLDOMDoctype, MLDOMElement, MLDOMElementCloseTag, MLDOMText } from './tokens'; | ||
/** | ||
* Specs | ||
*/ | ||
specs: SpecOM; | ||
/** | ||
* | ||
@@ -35,3 +30,3 @@ */ | ||
*/ | ||
constructor(ast: MLASTDocument, specs: SpecOM, ruleset: Ruleset); | ||
constructor(ast: MLASTDocument, ruleset: Ruleset); | ||
get doctype(): MLDOMDoctype<T, O> | null; | ||
@@ -38,0 +33,0 @@ get tree(): AnonymousNode<T, O>[]; |
@@ -38,5 +38,2 @@ "use strict"; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -47,7 +44,2 @@ var ml_ast_1 = require("@markuplint/ml-ast"); | ||
var helper_1 = require("./helper"); | ||
var html_ls_1 = __importDefault(require("@markuplint/html-ls")); | ||
var models = Object.keys(html_ls_1.default.def['#contentModels']).map(function (model) { return ({ | ||
name: model, | ||
contents: html_ls_1.default.def['#contentModels'][model], | ||
}); }); | ||
/** | ||
@@ -62,3 +54,3 @@ * markuplint DOM Document | ||
*/ | ||
function MLDOMDocument(ast, specs, ruleset) { | ||
function MLDOMDocument(ast, ruleset) { | ||
var _this = this; | ||
@@ -76,14 +68,9 @@ /** | ||
})); | ||
this.specs = specs; | ||
this.isFragment = ast.isFragment; | ||
for (var _i = 0, _a = this.tree; _i < _a.length; _i++) { | ||
// add rules to node | ||
for (var _i = 0, _a = this.nodeList; _i < _a.length; _i++) { | ||
var node = _a[_i]; | ||
recursiveResolveCategories(node); | ||
} | ||
// add rules to node | ||
for (var _b = 0, _c = this.nodeList; _b < _c.length; _b++) { | ||
var node = _c[_b]; | ||
// global rules | ||
for (var _d = 0, _e = Object.keys(ruleset.rules); _d < _e.length; _d++) { | ||
var ruleName = _e[_d]; | ||
for (var _b = 0, _c = Object.keys(ruleset.rules); _b < _c.length; _b++) { | ||
var ruleName = _c[_b]; | ||
var rule = ruleset.rules[ruleName]; | ||
@@ -97,4 +84,4 @@ node.rules[ruleName] = rule; | ||
// node specs and special rules for node by selector | ||
for (var _f = 0, _g = ruleset.nodeRules; _f < _g.length; _f++) { | ||
var nodeRule = _g[_f]; | ||
for (var _d = 0, _e = ruleset.nodeRules; _d < _e.length; _d++) { | ||
var nodeRule = _e[_d]; | ||
if (!nodeRule.rules) { | ||
@@ -112,4 +99,4 @@ continue; | ||
// special rules | ||
for (var _h = 0, _j = Object.keys(nodeRule.rules); _h < _j.length; _h++) { | ||
var ruleName = _j[_h]; | ||
for (var _f = 0, _g = Object.keys(nodeRule.rules); _f < _g.length; _f++) { | ||
var ruleName = _g[_f]; | ||
var rule = nodeRule.rules[ruleName]; | ||
@@ -121,4 +108,4 @@ node.rules[ruleName] = rule; | ||
// overwrite rule to child node | ||
for (var _k = 0, _l = ruleset.childNodeRules; _k < _l.length; _k++) { | ||
var nodeRule = _l[_k]; | ||
for (var _h = 0, _j = ruleset.childNodeRules; _h < _j.length; _h++) { | ||
var nodeRule = _j[_h]; | ||
if (!nodeRule.rules || !nodeRule.selector) { | ||
@@ -150,4 +137,4 @@ break; | ||
var this_1 = this; | ||
for (var _m = 0, _o = Object.keys(nodeRule.rules); _m < _o.length; _m++) { | ||
var ruleName = _o[_m]; | ||
for (var _k = 0, _l = Object.keys(nodeRule.rules); _k < _l.length; _k++) { | ||
var ruleName = _l[_k]; | ||
_loop_1(ruleName); | ||
@@ -245,87 +232,1 @@ } | ||
exports.default = MLDOMDocument; | ||
function getCategories(node) { | ||
var categories = []; | ||
switch (node.type) { | ||
case 'Text': { | ||
for (var _i = 0, models_1 = models; _i < models_1.length; _i++) { | ||
var model = models_1[_i]; | ||
if (model.contents.includes('#text')) { | ||
categories.push(model.name); | ||
} | ||
} | ||
break; | ||
} | ||
case 'Element': { | ||
for (var _a = 0, models_2 = models; _a < models_2.length; _a++) { | ||
var model = models_2[_a]; | ||
for (var _b = 0, _c = model.contents; _b < _c.length; _b++) { | ||
var selector = _c[_b]; | ||
if (/@/.test(selector)) { | ||
// TODO: | ||
continue; | ||
} | ||
if (node.matches(selector)) { | ||
categories.push(model.name); | ||
} | ||
} | ||
} | ||
break; | ||
} | ||
} | ||
return categories; | ||
} | ||
function resolveCategories(node) { | ||
switch (node.type) { | ||
case 'Text': { | ||
var ownCategories = getCategories(node); | ||
ownCategories.forEach(function (model) { return node.ownModels.add(model); }); | ||
break; | ||
} | ||
case 'Element': { | ||
/** | ||
* @see https://html.spec.whatwg.org/multipage/dom.html#phrasing-content | ||
* @revision 2019-10-21 | ||
* | ||
* > Most elements that are categorized as phrasing content can only contain elements that are themselves categorized as phrasing content, not any flow content. | ||
*/ | ||
var isPhrasingContent = true; | ||
var childModels = node.childNodes.map(getCategories); | ||
for (var _i = 0, childModels_1 = childModels; _i < childModels_1.length; _i++) { | ||
var models_3 = childModels_1[_i]; | ||
if (!models_3.includes('#phrasing')) { | ||
isPhrasingContent = false; | ||
break; | ||
} | ||
} | ||
var childCategories = childModels.flat(); | ||
var ownCategories = getCategories(node); | ||
ownCategories.forEach(function (model) { return node.ownModels.add(model); }); | ||
childCategories.forEach(function (model) { return node.childModels.add(model); }); | ||
if (!isPhrasingContent) { | ||
node.ownModels.delete('#phrasing'); | ||
} | ||
break; | ||
} | ||
} | ||
} | ||
function recursiveResolveCategories(node) { | ||
if (node.type === 'Element') { | ||
for (var _i = 0, _a = node.childNodes; _i < _a.length; _i++) { | ||
var child = _a[_i]; | ||
recursiveResolveCategories(child); | ||
} | ||
} | ||
resolveCategories(node); | ||
if (node.type === 'Element') { | ||
for (var _b = 0, _c = node.childNodes; _b < _c.length; _b++) { | ||
var child = _c[_b]; | ||
if (child.type === 'Element') { | ||
child.descendantModels.forEach(function (model) { return node.descendantModels.add(model); }); | ||
child.childModels.forEach(function (model) { return node.descendantModels.add(model); }); | ||
} | ||
} | ||
} | ||
} | ||
// function resolveCategories<T extends RuleConfigValue, O = null>(nodeList: AnonymousNode<T, O>[]) { | ||
// return nodeList.map(node => getCategories(node)); | ||
// } |
{ | ||
"name": "@markuplint/ml-core", | ||
"version": "1.0.0-alpha.13", | ||
"version": "1.0.0-alpha.14", | ||
"description": "The core module of markuplint", | ||
@@ -20,9 +20,9 @@ "repository": "git@github.com:markuplint/markuplint.git", | ||
"dependencies": { | ||
"@markuplint/i18n": "^1.0.0-alpha.5", | ||
"@markuplint/ml-ast": "^1.0.0-alpha.7", | ||
"@markuplint/ml-config": "^1.0.0-alpha.5", | ||
"@markuplint/ml-spec": "^1.0.0-alpha.4", | ||
"@markuplint/i18n": "^1.0.0-alpha.6", | ||
"@markuplint/ml-ast": "^1.0.0-alpha.8", | ||
"@markuplint/ml-config": "^1.0.0-alpha.6", | ||
"@markuplint/ml-spec": "^1.0.0-alpha.5", | ||
"css-selector-parser": "^1.3.0" | ||
}, | ||
"gitHead": "dd9dd6179298709e569c90bfdcfd659400b04f43" | ||
"gitHead": "40252ada7b745d85051eeb0e0401459a5fc58f51" | ||
} |
@@ -9,3 +9,3 @@ # @markuplint/ml-core | ||
Prerequisites: [Node.js](https://nodejs.org) (Version 8.0.0 or later) | ||
Prerequisites: [Node.js](https://nodejs.org) (Version 12.4.0 or later) | ||
@@ -12,0 +12,0 @@ ```sh |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
237136
1910