Skip to content

Commit

Permalink
fix: correct regex pattern for header
Browse files Browse the repository at this point in the history
  • Loading branch information
3w36zj6 committed Oct 9, 2024
1 parent ae530e0 commit 4c99f47
Show file tree
Hide file tree
Showing 5 changed files with 303 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/typstToTextlintAst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const convertTypstAstNodeTypeToTextlintNodeType = (
typstAstNodeType: string,
): string => {
const nodeTypeMap = new Map<RegExp, string>([
[/^Marked::Heading/, ASTNodeTypes.Header],
[/^Marked::Heading$/, ASTNodeTypes.Header],
[/^Marked::Text/, ASTNodeTypes.Str],
[/^Marked::Parbreak/, ASTNodeTypes.Break],
[/^Escape::Linebreak/, ASTNodeTypes.Break],
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/Header/input.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
= header 1

== header 2

=== header 3
295 changes: 295 additions & 0 deletions test/fixtures/Header/output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,295 @@
{
"children": [
{
"children": [
{
"value": "=",
"type": "Marked::HeadingMarker",
"raw": "=",
"range": [0, 1],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 1
}
}
},
{
"type": "Str",
"raw": " ",
"value": " ",
"range": [1, 2],
"loc": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 2
}
}
},
{
"children": [
{
"value": "header 1",
"type": "Str",
"raw": "header 1",
"range": [2, 10],
"loc": {
"start": {
"line": 1,
"column": 2
},
"end": {
"line": 1,
"column": 10
}
}
}
],
"type": "Marked::Markup",
"raw": "header 1",
"range": [2, 10],
"loc": {
"start": {
"line": 1,
"column": 2
},
"end": {
"line": 1,
"column": 10
}
}
}
],
"type": "Header",
"raw": "= header 1",
"range": [0, 10],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 10
}
}
},
{
"value": "\n\n",
"type": "Break",
"raw": "\n\n",
"range": [10, 12],
"loc": {
"start": {
"line": 1,
"column": 10
},
"end": {
"line": 3,
"column": 0
}
}
},
{
"children": [
{
"value": "==",
"type": "Marked::HeadingMarker",
"raw": "==",
"range": [12, 14],
"loc": {
"start": {
"line": 3,
"column": 0
},
"end": {
"line": 3,
"column": 2
}
}
},
{
"type": "Str",
"raw": " ",
"value": " ",
"range": [14, 15],
"loc": {
"start": {
"line": 3,
"column": 2
},
"end": {
"line": 3,
"column": 3
}
}
},
{
"children": [
{
"value": "header 2",
"type": "Str",
"raw": "header 2",
"range": [15, 23],
"loc": {
"start": {
"line": 3,
"column": 3
},
"end": {
"line": 3,
"column": 11
}
}
}
],
"type": "Marked::Markup",
"raw": "header 2",
"range": [15, 23],
"loc": {
"start": {
"line": 3,
"column": 3
},
"end": {
"line": 3,
"column": 11
}
}
}
],
"type": "Header",
"raw": "== header 2",
"range": [12, 23],
"loc": {
"start": {
"line": 3,
"column": 0
},
"end": {
"line": 3,
"column": 11
}
}
},
{
"value": "\n\n",
"type": "Break",
"raw": "\n\n",
"range": [23, 25],
"loc": {
"start": {
"line": 3,
"column": 11
},
"end": {
"line": 5,
"column": 0
}
}
},
{
"children": [
{
"value": "===",
"type": "Marked::HeadingMarker",
"raw": "===",
"range": [25, 28],
"loc": {
"start": {
"line": 5,
"column": 0
},
"end": {
"line": 5,
"column": 3
}
}
},
{
"type": "Str",
"raw": " ",
"value": " ",
"range": [28, 29],
"loc": {
"start": {
"line": 5,
"column": 3
},
"end": {
"line": 5,
"column": 4
}
}
},
{
"children": [
{
"value": "header 3",
"type": "Str",
"raw": "header 3",
"range": [29, 37],
"loc": {
"start": {
"line": 5,
"column": 4
},
"end": {
"line": 5,
"column": 12
}
}
}
],
"type": "Marked::Markup",
"raw": "header 3",
"range": [29, 37],
"loc": {
"start": {
"line": 5,
"column": 4
},
"end": {
"line": 5,
"column": 12
}
}
}
],
"type": "Header",
"raw": "=== header 3",
"range": [25, 37],
"loc": {
"start": {
"line": 5,
"column": 0
},
"end": {
"line": 5,
"column": 12
}
}
}
],
"type": "Document",
"raw": "= header 1\n\n== header 2\n\n=== header 3",
"range": [0, 37],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 5,
"column": 12
}
}
}
2 changes: 1 addition & 1 deletion test/paragraphizedTextlintAstObject.json
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@
"children": [
{
"value": "=",
"type": "Header",
"type": "Marked::HeadingMarker",
"raw": "=",
"range": [68, 69],
"loc": {
Expand Down
2 changes: 1 addition & 1 deletion test/textlintAstObject.json
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@
"children": [
{
"value": "=",
"type": "Header",
"type": "Marked::HeadingMarker",
"raw": "=",
"range": [68, 69],
"loc": {
Expand Down

0 comments on commit 4c99f47

Please sign in to comment.