Skip to content

Commit fedaf20

Browse files
committed
feat: support MyST
Closes #667. Signed-off-by: Joseph Kato <joseph@jdkato.io>
1 parent eec788d commit fedaf20

10 files changed

Lines changed: 739 additions & 2 deletions

File tree

‎internal/core/format.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ var FormatByExtension = map[string][]string{
7474
`\.(?:lua)$`: {".lua", "code"},
7575
`\.(?:md|mdown|markdown|markdn|[Rr]md)$`: {".md", "markup"},
7676
`\.(?:mdx)$`: {".mdx", "markup"},
77+
`\.(?:myst)$`: {".myst", "markup"},
7778
`\.(?:org)$`: {".org", "markup"},
7879
`\.(?:php)$`: {".php", "code"},
7980
`\.(?:pl|pm|pod)$`: {".r", "code"},

‎internal/lint/ast.go‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ var inlineTags = []string{
2323
"b", "big", "i", "small", "abbr", "acronym", "cite", "dfn", "em", "kbd",
2424
"strong", "a", "br", "img", "span", "sub", "sup", "code", "tt", "del"}
2525

26+
// voidTags never carry content, so they are never "open" as containers.
27+
var voidTags = []string{
28+
"area", "base", "br", "col", "embed", "hr", "img", "input", "link",
29+
"meta", "source", "track", "wbr"}
30+
2631
// inlineToScope names the inline elements that can be scoped on their own.
2732
//
2833
// These are siblings of `text`, not children of it: a scope of `text` is
@@ -92,6 +97,13 @@ func (l *Linter) lintHTMLTokens(f *core.File, raw []byte, offset int) error { //
9297
class = getAttribute(tok, "class")
9398
skipClass = checkClasses(class, skipClasses)
9499

100+
if tokt == html.StartTagToken && !core.StringInSlice(txt, inlineTags) &&
101+
!core.StringInSlice(txt, voidTags) {
102+
walker.enclose(txt, class)
103+
} else if tokt == html.EndTagToken && !core.StringInSlice(txt, inlineTags) {
104+
walker.unclose(txt)
105+
}
106+
95107
blockSkip := skipClass && !core.StringInSlice(txt, inlineTags)
96108
if tokt == html.ErrorToken { //nolint:gocritic
97109
break

‎internal/lint/html.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ var blockDelimiters = map[string]string{
3232
".adoc": "\n----\n$1\n----\n",
3333
".md": "\n```\n$1\n```\n",
3434
".mdx": "\n```\n$1\n```\n",
35+
".myst": "\n```\n$1\n```\n",
3536
".rst": "\n::\n\n%s\n",
3637
".org": orgExample,
3738
}
@@ -84,6 +85,7 @@ var inlineDelimiters = map[string]string{
8485
".adoc": "`$1`",
8586
".md": "`$1`",
8687
".mdx": "`$1`",
88+
".myst": "`$1`",
8789
".rst": "``$1``",
8890
".org": "=$1=",
8991
}

‎internal/lint/lint.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ func (l *Linter) lintFile(src string) lintResult {
246246
err = l.lintMarkdown(file)
247247
case ".mdx":
248248
err = l.lintMDX(file)
249+
case ".myst":
250+
err = l.lintMyST(file)
249251
case ".rst":
250252
err = l.lintRST(file)
251253
case ".xml", ".xsd":

‎internal/lint/md.go‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ var reLinkDef = regexp.MustCompile(`\[(?:[^]\n]+)\]:`)
3737
var reNumericList = regexp.MustCompile(`(?m)^\d+\.`)
3838

3939
func (l *Linter) lintMarkdown(f *core.File) error {
40+
return l.lintMarkdownWith(f, goldMd)
41+
}
42+
43+
// lintMarkdownWith lints f as Markdown read by the given converter -- the
44+
// plain configuration, or a dialect's such as MyST's.
45+
func (l *Linter) lintMarkdownWith(f *core.File, md goldmark.Markdown) error {
4046
var buf bytes.Buffer
4147

4248
err := l.lintMetadata(f)
@@ -49,7 +55,7 @@ func (l *Linter) lintMarkdown(f *core.File) error {
4955
return err
5056
}
5157

52-
if err = goldMd.Convert([]byte(s), &buf); err != nil {
58+
if err = md.Convert([]byte(s), &buf); err != nil {
5359
return core.NewE100(f.Path, err)
5460
}
5561

0 commit comments

Comments
 (0)