[GITEA] Require Latex code to have a end sequence
- Currently the parser will look for `\[` and `$$` to detect when Latex code starts, it will look for `\]` and `$$` respectively in order to determine the end of the code. However if no end is found the parser assumes the rest of the input is part of the Latex code. - Adjust the parser's behavior to not allow the case to assume the rest of the input is part of the Latex code and requires in order to determine if some input is Latex code that the end sequence is also specified. - Example: `\[hello]` would no longer be detected as Latex code with this patch. - Added unit tests. - Resolves https://codeberg.org/forgejo/forgejo/issues/1817 (cherry picked from commit452aef1bb1
) (cherry picked from commit8a857c24b0
) (cherry picked from commitacd1456db9
) (cherry picked from commit6523b45073
) (cherry picked from commite2e1a8afe7
) (cherry picked from commita46ef652eb
) (cherry picked from commit54d5a8c073
) (cherry picked from commit4a88dc6416
)
This commit is contained in:
parent
49c39f0ed5
commit
f88b58be3f
2 changed files with 13 additions and 4 deletions
|
@ -524,6 +524,18 @@ func TestMathBlock(t *testing.T) {
|
||||||
"$$a$$",
|
"$$a$$",
|
||||||
`<pre class="code-block is-loading"><code class="chroma language-math display">a</code></pre>` + nl,
|
`<pre class="code-block is-loading"><code class="chroma language-math display">a</code></pre>` + nl,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
`\[a b\]`,
|
||||||
|
`<pre class="code-block is-loading"><code class="chroma language-math display">a b</code></pre>` + nl,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
`\[a b]`,
|
||||||
|
`<p>[a b]</p>` + nl,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
`$$a`,
|
||||||
|
`<p>$$a</p>` + nl,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range testcases {
|
for _, test := range testcases {
|
||||||
|
|
|
@ -55,10 +55,7 @@ func (b *blockParser) Open(parent ast.Node, reader text.Reader, pc parser.Contex
|
||||||
return node, parser.Close | parser.NoChildren
|
return node, parser.Close | parser.NoChildren
|
||||||
}
|
}
|
||||||
|
|
||||||
reader.Advance(segment.Len() - 1)
|
return nil, parser.NoChildren
|
||||||
segment.Start += 2
|
|
||||||
node.Lines().Append(segment)
|
|
||||||
return node, parser.NoChildren
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Continue parses the current line and returns a result of parsing.
|
// Continue parses the current line and returns a result of parsing.
|
||||||
|
|
Loading…
Reference in a new issue