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

docs: remove old docs folder and replace with new one #2816

Closed
wants to merge 5 commits into from
Closed
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
93 changes: 93 additions & 0 deletions .github/actions/markdown-lint-rules/admonition.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// @ts-check

"use strict";

module.exports = {
"names": [ "github-admonition" ],
"description": "asdfg",
"information": new URL(
"https://github.com/aepfli/markdownlint-rule-max-one-sentence-per-line"
),
"tags": [ "admonition" ],
"function": (params, onError) => {
const admonitions = params.config.admonitions || [ "Note", "Warning" ];
const admonitionStart = params.config.start || "> **";
const admonitionEnd = params.config.end ||"**";

const atBeginningRegex =
new RegExp("^([\\n\\t ]*)(.*)(" +
admonitions.join("|") +
")(:?\\*\\*)", "im");

const atBeginning =
(relevantToken) => {
const check = atBeginningRegex.exec(relevantToken.line);
if (check && (check[2] !== "> **" ||
!admonitions.includes(check[3]) ||
check[4] !== "**")) {
const lengthForReplacement =
check[2].length + check[3].length + check[4].length;
const position = check[1].length + 1;
onError({
"lineNumber": relevantToken.lineNumber,
"detail": relevantToken.line.substr(0, 10),
"fixInfo": {
"lineNumber": relevantToken.lineNumber,
"editColumn": position,
"deleteCount": lengthForReplacement,
// eslint-disable-next-line max-len
"insertText": admonitionStart + check[3].charAt(0).toUpperCase() + check[3].slice(1).toLowerCase() + admonitionEnd
}
});
}
};

const wholeLineRegex =
new RegExp("^([\\n\\t ]*)(.*)(" +
admonitions.join("|") +
"):?(.*)(\\*\\*)", "im");

const wholeLine =
(relevantToken) => {
const check = wholeLineRegex
.exec(relevantToken.line);
if (check && (check[2] !== "> **" ||
!admonitions.includes(check[3]) ||
check[5] !== "**")) {
const position = check[1] ? check[1].length + 1 : 1;

const lengthForReplacement = relevantToken.line.length - position + 1;
const replacement = admonitionStart +
check[3].charAt(0).toUpperCase() + check[3].slice(1).toLowerCase() +
admonitionEnd +
check[4];

onError({
"lineNumber": relevantToken.lineNumber,
"detail": relevantToken.line.substr(0, 10),
"fixInfo": {
"lineNumber": relevantToken.lineNumber,
"editColumn": position,
"deleteCount": lengthForReplacement,

"insertText": replacement
}
});
}
};

const relevantTokens = [];
for (let i = 0; i < params.tokens.length; i++) {
const token = params.tokens[i];
if (token.type === "paragraph_open" &&
params.tokens[i + 1].type === "inline") {
relevantTokens.push(params.tokens[i + 1]);
}
}

for (const relevantToken of relevantTokens) {
atBeginning(relevantToken);
wholeLine(relevantToken);
}
}
};
100 changes: 100 additions & 0 deletions .github/actions/markdown-lint-rules/max-one-sentence-per-line.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// @ts-check

"use strict";

const indentFor = (string, indentation) => {
// eslint-disable-next-line max-len
const regex = new RegExp("^(?<indents>(" + indentation + ")*)(?<adds>- |> |>|\\* |\\d+\\. )?");
const match = regex.exec(string);
if (!match) {
return "";
}
let indentSize = 0;
if (match.groups.indents) {
indentSize = match.groups.indents.length / indentation.length;
}
if (match.groups.adds) {
if (match.groups.adds.includes(">")) {
return indentation.repeat(indentSize) + match.groups.adds;
}
indentSize++;
}
return indentation.repeat(indentSize);
};

const isAfterIgnoredWord = (ignoredWords, line, i) => {
for (const ignoredWord of ignoredWords) {
const lastWordInLine = line.substring(i - ignoredWord.length, i);
if (ignoredWord === lastWordInLine.toLowerCase()) {
return true;
}
}

return false;
};

module.exports = {
"names": [ "max-one-sentence-per-line" ],
"description": "Max 1 sentence should be on a line",
"information": new URL(
"https://github.com/aepfli/markdownlint-rule-max-one-sentence-per-line"
),
"tags": [ "sentences" ],
"function": (params, onError) => {

const ignoredWords = params.config.ignored_words ||
[ "ie", "i.e", "eg", "e.g", "etc", "ex" ];
const lineEndings = params.config.line_endings || [ ".", "?", "!" ];
const sentenceStartRegex = params.config.sentence_start ||
"^\\s+(\\w|[*_'\"])";
const contextSize = Number(params.config.context_length || 14);
const indentation = params.config.indentation || " ";

const sentenceStart = new RegExp(sentenceStartRegex);

const relevantTokens = [];
for (let i = 0; i < params.tokens.length; i++) {
const token = params.tokens[i];
if (token.type === "paragraph_open" &&
params.tokens[i + 1].type === "inline") {
relevantTokens.push(params.tokens[i + 1]);
}
}

for (const relevantToken of relevantTokens) {

for (const token of relevantToken.children) {
const lineNumber = token.lineNumber;
if (token.type === "text") {
const content = token.content;
for (let i = 0; i < content.length - 2; i += 1) {

if (lineEndings.includes(content[i])) {
const sentence = sentenceStart.exec(content.substr(i + 1));
if (
sentence !== null &&
!isAfterIgnoredWord(ignoredWords, content, i)
) {
const spaces = sentence[1];
const pointInLine = token.line.indexOf(content) + i;
onError({
"lineNumber": lineNumber,
"detail": null,
// eslint-disable-next-line max-len
"context": content.substr(Math.max(0, i - (contextSize / 2)), contextSize),
"range": [ pointInLine, spaces.length ], "fixInfo": {
"lineNumber": lineNumber,
"editColumn": pointInLine + 2,
"deleteCount": spaces.length,
// eslint-disable-next-line max-len
"insertText": "\n" + indentFor(relevantToken.line, indentation)
}
});
}
}
}
}
}
}
}
};
Loading
Loading