@markuplint/ml-core
Advanced tools
Comparing version 1.0.0-alpha.9 to 1.0.0-alpha.10
import { AnonymousNode, Document } from '../'; | ||
import { MLASTElement, MLToken } from '@markuplint/ml-ast'; | ||
import { MLDOMAttribute, MLDOMElementCloseTag, MLDOMNode, MLDOMToken } from './'; | ||
import { MLDOMAttribute, MLDOMElementCloseTag, MLDOMNode, MLDOMText, MLDOMToken } from './'; | ||
import { IMLDOMElement } from '../types'; | ||
@@ -24,4 +24,5 @@ import { RuleConfigValue } from '@markuplint/ml-config'; | ||
fixNodeName(name: string): void; | ||
getChildElementsAndTextNodeWithoutWhitespaces(): (MLDOMElement<T, O> | MLDOMText<T, O>)[]; | ||
readonly classList: string[]; | ||
readonly id: string; | ||
} |
@@ -75,2 +75,18 @@ "use strict"; | ||
}; | ||
MLDOMElement.prototype.getChildElementsAndTextNodeWithoutWhitespaces = function () { | ||
var filteredNodes = []; | ||
this.childNodes.forEach(function (node) { | ||
if (node.type === 'Element') { | ||
filteredNodes.push(node); | ||
} | ||
if (node.type === 'Text' && !node.isWhitespace()) { | ||
filteredNodes.push(node); | ||
} | ||
if (node.type === 'OmittedElement') { | ||
var children = node.getChildElementsAndTextNodeWithoutWhitespaces(); | ||
filteredNodes.push.apply(filteredNodes, children); | ||
} | ||
}); | ||
return filteredNodes; | ||
}; | ||
Object.defineProperty(MLDOMElement.prototype, "classList", { | ||
@@ -77,0 +93,0 @@ get: function () { |
@@ -0,5 +1,7 @@ | ||
import { AnonymousNode, IMLDOMOmittedElement } from '../types'; | ||
import Document from '../document'; | ||
import { IMLDOMOmittedElement } from '../types'; | ||
import { MLASTOmittedElement } from '@markuplint/ml-ast'; | ||
import MLDOMElement from './element'; | ||
import MLDOMNode from './node'; | ||
import MLDOMText from './text'; | ||
import { RuleConfigValue } from '@markuplint/ml-config'; | ||
@@ -13,2 +15,4 @@ export default class MLDOMOmittedElement<T extends RuleConfigValue, O = null> extends MLDOMNode<T, O, MLASTOmittedElement> implements IMLDOMOmittedElement { | ||
constructor(astNode: MLASTOmittedElement, document: Document<T, O>); | ||
readonly childNodes: AnonymousNode<T, O>[]; | ||
getChildElementsAndTextNodeWithoutWhitespaces(): (MLDOMElement<T, O> | MLDOMText<T, O>)[]; | ||
} |
@@ -20,2 +20,3 @@ "use strict"; | ||
var node_1 = __importDefault(require("./node")); | ||
var helper_1 = require("../helper"); | ||
var MLDOMOmittedElement = /** @class */ (function (_super) { | ||
@@ -32,4 +33,28 @@ __extends(MLDOMOmittedElement, _super); | ||
} | ||
Object.defineProperty(MLDOMOmittedElement.prototype, "childNodes", { | ||
get: function () { | ||
var astChildren = this._astToken.childNodes || []; | ||
return astChildren.map(function (node) { return helper_1.getNode(node); }); | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
MLDOMOmittedElement.prototype.getChildElementsAndTextNodeWithoutWhitespaces = function () { | ||
var filteredNodes = []; | ||
this.childNodes.forEach(function (node) { | ||
if (node.type === 'Element') { | ||
filteredNodes.push(node); | ||
} | ||
if (node.type === 'Text' && !node.isWhitespace()) { | ||
filteredNodes.push(node); | ||
} | ||
if (node.type === 'OmittedElement') { | ||
var children = node.getChildElementsAndTextNodeWithoutWhitespaces(); | ||
filteredNodes.push.apply(filteredNodes, children); | ||
} | ||
}); | ||
return filteredNodes; | ||
}; | ||
return MLDOMOmittedElement; | ||
}(node_1.default)); | ||
exports.default = MLDOMOmittedElement; |
@@ -11,2 +11,3 @@ import { Document } from '../'; | ||
constructor(astNode: MLASTText, document: Document<T, O>); | ||
isWhitespace(): boolean; | ||
/** | ||
@@ -13,0 +14,0 @@ * @override |
@@ -35,2 +35,5 @@ "use strict"; | ||
} | ||
MLDOMText.prototype.isWhitespace = function () { | ||
return /^\s+$/.test(this.raw); | ||
}; | ||
Object.defineProperty(MLDOMText.prototype, "indentation", { | ||
@@ -37,0 +40,0 @@ /** |
@@ -16,3 +16,3 @@ import { RuleConfig, RuleConfigValue, RuleInfo, Severity, VerifiedResult } from '@markuplint/ml-config'; | ||
fix(document: Document<T, O>, rule: RuleInfo<T, O>): Promise<void>; | ||
optimizeOption(option: T | RuleConfig<T, O>): RuleInfo<T, O>; | ||
optimizeOption(configSettings: T | RuleConfig<T, O>): RuleInfo<T, O>; | ||
} |
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -98,6 +109,6 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
MLRule.prototype.optimizeOption = function (option) { | ||
if (typeof option === 'boolean') { | ||
MLRule.prototype.optimizeOption = function (configSettings) { | ||
if (typeof configSettings === 'boolean') { | ||
return { | ||
disabled: !option, | ||
disabled: !configSettings, | ||
severity: this.defaultServerity, | ||
@@ -108,10 +119,15 @@ value: this.defaultValue, | ||
} | ||
if (!Array.isArray(option) && typeof option === 'object' && option !== null) { | ||
if (!Array.isArray(configSettings) && typeof configSettings === 'object' && configSettings !== null) { | ||
return { | ||
disabled: false, | ||
severity: option.severity || this.defaultServerity, | ||
value: option.value !== undefined ? option.value : this.defaultValue, | ||
option: this.defaultOptions !== null && typeof this.defaultOptions === 'object' | ||
? Object.assign({}, this.defaultOptions, option.option || {}) | ||
: option.option || this.defaultOptions, | ||
severity: configSettings.severity || this.defaultServerity, | ||
value: configSettings.value !== undefined ? configSettings.value : this.defaultValue, | ||
option: Array.isArray(this.defaultOptions) | ||
? configSettings.option | ||
? // prettier-ignore | ||
// @ts-ignore for "as" casting | ||
this.defaultOptions.concat(configSettings.option) | ||
: this.defaultOptions | ||
: this.defaultOptions !== null && typeof this.defaultOptions === 'object' | ||
? __assign(__assign({}, this.defaultOptions), (configSettings.option || {})) : configSettings.option || this.defaultOptions, | ||
}; | ||
@@ -123,3 +139,3 @@ } | ||
// @ts-ignore TODO: Wait for fix to bug of type guards in TypeScript | ||
value: option == null ? this.defaultValue : option, | ||
value: configSettings == null ? this.defaultValue : configSettings, | ||
option: this.defaultOptions, | ||
@@ -126,0 +142,0 @@ }; |
{ | ||
"name": "@markuplint/ml-core", | ||
"version": "1.0.0-alpha.9", | ||
"version": "1.0.0-alpha.10", | ||
"description": "The core module of markuplint", | ||
@@ -26,3 +26,3 @@ "repository": "git@github.com:markuplint/markuplint.git", | ||
}, | ||
"gitHead": "9e77270cab9fedc1ee16dbaa59ffbe6e65fb6a3e" | ||
"gitHead": "c641faacf69229f2ace793454a6ebd615b8249ff" | ||
} |
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
231474
1847