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

FIX: set correct end line #11

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,23 +115,26 @@
let { endpos } = outcome
endpos += begin

let line = startLine
while (line < endLine) {
if (endpos >= state.bMarks[line] && endpos <= state.eMarks[line]) {
// Find the final line of the amsmath block
let nextLine = startLine
for (; nextLine < endLine; nextLine++) {
if (endpos >= state.bMarks[nextLine] && endpos <= state.eMarks[nextLine]) {
// line for end of block math found ...
// eslint-disable-next-line no-param-reassign
state.line = line + 1
break
}
line += 1
}
// Skip over the final amsmath line
nextLine += 1;

Check failure on line 128 in src/index.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `;`
rowanc1 marked this conversation as resolved.
Show resolved Hide resolved
// Write back to the state
state.line = nextLine;

Check failure on line 130 in src/index.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `;`
rowanc1 marked this conversation as resolved.
Show resolved Hide resolved

if (!silent) {
const token = state.push("amsmath", "math", 0)
token.block = true
token.content = state.src.slice(begin, endpos)
token.meta = { environment, numbered }
token.map = [startLine, line]
token.map = [startLine, nextLine]
}

return true
Expand Down
55 changes: 54 additions & 1 deletion tests/fixtures.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect, it } from "vitest"
import { describe, expect, test, it } from "vitest"
import fs from "node:fs"
import katex from "katex"
import MarkdownIt from "markdown-it"
Expand Down Expand Up @@ -37,3 +37,56 @@ describe("Parses basic", () => {
it(name, () => expect(rendered.trim()).toEqual(expected.trim()))
})
})

test("Produces correct tokens", () => {
const mdit = MarkdownIt().use(amsmathPlugin)
const tokens = mdit.parse(`
\\begin{equation}
y = m * x + c \\
z = 2
\\end{equation}
Hello world!
`)
expect(tokens).toMatchObject([
{
type: "amsmath",
map: [1, 5],
nesting: 0,
level: 0,
content: "\\begin{equation}\ny = m * x + c \\\nz = 2\n\\end{equation}",
meta: { environment: "equation", numbered: "" },
block: true,
hidden: false
},
{
type: "paragraph_open",
map: [5, 6],
nesting: 1,
level: 0,
content: "",
meta: null,
block: true,
hidden: false
},
{
type: "inline",
map: [5, 6],
nesting: 0,
level: 1,
content: "Hello world!",
meta: null,
block: true,
hidden: false
},
{
type: "paragraph_close",
map: null,
nesting: -1,
level: 0,
content: "",
meta: null,
block: true,
hidden: false
}
])
})
Loading