Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidAnson committed Jul 23, 2023
1 parent 947f9db commit d4d07c6
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 64 deletions.
115 changes: 66 additions & 49 deletions demo/markdownlint-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -5138,83 +5138,100 @@ module.exports = {
"function": function MD037(params, onError) {
var lines = params.lines,
parsers = params.parsers;
var emphasisTokensByMarker = new Map();
for (var _i = 0, _arr = ["_", "__", "___", "*", "**", "***"]; _i < _arr.length; _i++) {
var marker = _arr[_i];
emphasisTokensByMarker.set(marker, []);
}
var pending = _toConsumableArray(parsers.micromark.tokens);
var token = null;
while (token = pending.shift()) {
// Reparse htmlFlow tokens, queue children
if (token.type === "htmlFlow") {
// pending.unshift(...reparseHtmlFlowToken(token, lines));
// console.dir(reparseHtmlFlowToken(token, lines))
pending.unshift.apply(pending, _toConsumableArray(token.htmlFlowChildren));
// console.dir(token.htmlFlowChildren)
continue;
}
pending.push.apply(pending, _toConsumableArray(token.children));

// Build lists of bare tokens for each emphasis marker type
var emphasisTokensByMarker = {
"_": [],
"__": [],
"___": [],
"*": [],
"**": [],
"***": []
};
var _iterator = _createForOfIteratorHelper(token.children),
var _iterator = _createForOfIteratorHelper(emphasisTokensByMarker.values()),
_step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var child = _step.value;
var emphasisTokens = _step.value;
emphasisTokens.length = 0;
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
var _iterator2 = _createForOfIteratorHelper(token.children),
_step2;
try {
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
var child = _step2.value;
var text = child.text,
type = child.type;
if (type === "data" && emphasisTokensByMarker[text]) {
emphasisTokensByMarker[text].push(child);
if (type === "data") {
var _emphasisTokens = emphasisTokensByMarker.get(text);
if (_emphasisTokens) {
_emphasisTokens.push(child);
}
}
}

// Process bare tokens for each emphasis marker type
} catch (err) {
_iterator.e(err);
_iterator2.e(err);
} finally {
_iterator.f();
_iterator2.f();
}
for (var _i = 0, _Object$values = Object.values(emphasisTokensByMarker); _i < _Object$values.length; _i++) {
var emphasisTokens = _Object$values[_i];
for (var i = 0; i + 1 < emphasisTokens.length; i += 2) {
// Process start token of start/end pair
var startToken = emphasisTokens[i];
var startText = lines[startToken.startLine - 1].slice(startToken.startColumn - 1);
var startMatch = startText.match(emphasisStartTextRe);
if (startMatch) {
var _startMatch = _slicedToArray(startMatch, 3),
startContext = _startMatch[0],
startMarker = _startMatch[1],
startSpaces = _startMatch[2];
if (startMarker === startToken.text && startSpaces.length > 0) {
addError(onError, startToken.startLine, undefined, startContext, [startToken.startColumn, startContext.length], {
"editColumn": startToken.endColumn,
"deleteCount": startSpaces.length
});
var _iterator3 = _createForOfIteratorHelper(emphasisTokensByMarker.values()),
_step3;
try {
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
var _emphasisTokens2 = _step3.value;
for (var i = 0; i + 1 < _emphasisTokens2.length; i += 2) {
// Process start token of start/end pair
var startToken = _emphasisTokens2[i];
var startText = lines[startToken.startLine - 1].slice(startToken.startColumn - 1);
var startMatch = startText.match(emphasisStartTextRe);
if (startMatch) {
var _startMatch = _slicedToArray(startMatch, 3),
startContext = _startMatch[0],
startMarker = _startMatch[1],
startSpaces = _startMatch[2];
if (startMarker === startToken.text && startSpaces.length > 0) {
addError(onError, startToken.startLine, undefined, startContext, [startToken.startColumn, startContext.length], {
"editColumn": startToken.endColumn,
"deleteCount": startSpaces.length
});
}
}
}

// Process end token of start/end pair
var endToken = emphasisTokens[i + 1];
var endText = lines[endToken.startLine - 1].slice(0, endToken.endColumn - 1);
var endMatch = endText.match(emphasisEndTextRe);
if (endMatch) {
var _endMatch = _slicedToArray(endMatch, 3),
endContext = _endMatch[0],
endSpace = _endMatch[1],
endMarker = _endMatch[2];
if (endMarker === endToken.text && endSpace.length > 0) {
addError(onError, endToken.startLine, undefined, endContext, [endToken.endColumn - endContext.length, endContext.length], {
"editColumn": endToken.startColumn - endSpace.length,
"deleteCount": endSpace.length
});
// Process end token of start/end pair
var endToken = _emphasisTokens2[i + 1];
var endText = lines[endToken.startLine - 1].slice(0, endToken.endColumn - 1);
var endMatch = endText.match(emphasisEndTextRe);
if (endMatch) {
var _endMatch = _slicedToArray(endMatch, 3),
endContext = _endMatch[0],
endSpace = _endMatch[1],
endMarker = _endMatch[2];
if (endMarker === endToken.text && endSpace.length > 0) {
addError(onError, endToken.startLine, undefined, endContext, [endToken.endColumn - endContext.length, endContext.length], {
"editColumn": endToken.startColumn - endSpace.length,
"deleteCount": endSpace.length
});
}
}
}
}
} catch (err) {
_iterator3.e(err);
} finally {
_iterator3.f();
}
}
}
Expand Down
27 changes: 13 additions & 14 deletions lib/md037.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,37 @@ module.exports = {
"tags": [ "whitespace", "emphasis" ],
"function": function MD037(params, onError) {
const { lines, parsers } = params;
const emphasisTokensByMarker = new Map();
for (const marker of [ "_", "__", "___", "*", "**", "***" ]) {
emphasisTokensByMarker.set(marker, []);
}
const pending = [ ...parsers.micromark.tokens ];
let token = null;
while ((token = pending.shift())) {

// Reparse htmlFlow tokens, queue children
if (token.type === "htmlFlow") {
// pending.unshift(...reparseHtmlFlowToken(token, lines));
// console.dir(reparseHtmlFlowToken(token, lines))
pending.unshift(...token.htmlFlowChildren);
// console.dir(token.htmlFlowChildren)
continue;
}
pending.push(...token.children);

// Build lists of bare tokens for each emphasis marker type
const emphasisTokensByMarker = {
"_": [],
"__": [],
"___": [],
"*": [],
"**": [],
"***": []
};
for (const emphasisTokens of emphasisTokensByMarker.values()) {
emphasisTokens.length = 0;
}
for (const child of token.children) {
const { text, type } = child;
if ((type === "data") && (emphasisTokensByMarker[text])) {
emphasisTokensByMarker[text].push(child);
if (type === "data") {
const emphasisTokens = emphasisTokensByMarker.get(text);
if (emphasisTokens) {
emphasisTokens.push(child);
}
}
}

// Process bare tokens for each emphasis marker type
for (const emphasisTokens of Object.values(emphasisTokensByMarker)) {
for (const emphasisTokens of emphasisTokensByMarker.values()) {
for (let i = 0; i + 1 < emphasisTokens.length; i += 2) {

// Process start token of start/end pair
Expand Down
4 changes: 3 additions & 1 deletion test/snapshots/markdownlint-test-repos.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ Generated by [AVA](https://avajs.dev).
`test-repos/dotnet-docs/docs/azure/sdk/includes/assign-local-dev-group-to-role-azure-portal-4.md: 5: MD032/blanks-around-lists Lists should be surrounded by blank lines [Context: "<br>"]␊
test-repos/dotnet-docs/docs/azure/sdk/includes/assign-managed-identity-to-role-azure-portal-4.md: 5: MD032/blanks-around-lists Lists should be surrounded by blank lines [Context: "<br>"]␊
test-repos/dotnet-docs/docs/azure/sdk/includes/assign-service-principal-to-role-azure-portal-4.md: 5: MD032/blanks-around-lists Lists should be surrounded by blank lines [Context: "<br>"]␊
test-repos/dotnet-docs/docs/core/compatibility/core-libraries/5.0/code-access-security-apis-obsolete.md: 431: MD033/no-inline-html Inline HTML [Element: StrongName]`
test-repos/dotnet-docs/docs/core/compatibility/core-libraries/5.0/code-access-security-apis-obsolete.md: 431: MD033/no-inline-html Inline HTML [Element: StrongName]␊
test-repos/dotnet-docs/docs/core/extensions/windows-service.md: 177: MD037/no-space-in-emphasis Spaces inside emphasis markers [Context: "n *"]␊
test-repos/dotnet-docs/docs/devops/github-actions-overview.md: 32: MD037/no-space-in-emphasis Spaces inside emphasis markers [Context: "r *"]`

## https://github.com/electron/electron

Expand Down
Binary file modified test/snapshots/markdownlint-test-repos.js.snap
Binary file not shown.

0 comments on commit d4d07c6

Please sign in to comment.