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

Added minted environment #78

Merged
merged 2 commits into from
Feb 18, 2024
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ debugging
.vscode
vscode*
table-generation/generated
.wireit
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### v1.6.1
- Pass `VisitInfo` as an additional argument ot `macroReplacers` and `environmentReplacers` in `unifiedLatexToHast`.
- Allow skipping of HTML validation in `unifiedLatexToHast`.
- The `minted` environment parses its contents as a verbatim.

### v1.6.0
- Embellishment tokens are now supported in macro `signature`s. E.g., a `xxx: {signature: "e{^_}"}` will allow `\xxx_{foo}^{bar}` and `\xxx^{foo}_{bar}` to parse correctly.
Expand Down
51 changes: 35 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion packages/unified-latex-ctan/package/minted/provides.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ export const macros: MacroInfoRecord = {
newmintedfile: { signature: "o m m" },
};

export const environments: EnvInfoRecord = {};
export const environments: EnvInfoRecord = {
minted: { signature: "o m" },
};
100 changes: 0 additions & 100 deletions packages/unified-latex-util-parse/tests/parse-basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,104 +140,4 @@ describe("unified-latex-util-parse", () => {
parsed = parseMath("\\x #1 y");
expect(printRaw(parsed)).toEqual("\\x #1 y");
});

it("Parses verbatim arguments directly as strings", () => {
expect(trimRenderInfo(parse("\\lstinline{some_code$}"))).toEqual({
type: "root",
content: [
m("lstinline", args([null, "some_code$"], { braces: "[]{}" })),
],
});
expect(
trimRenderInfo(parse("\\lstinline[language]{some_code$}"))
).toEqual({
type: "root",
content: [
m(
"lstinline",
args(["language", "some_code$"], { braces: "[]{}" })
),
],
});
expect(trimRenderInfo(parse("\\lstinline#some_code$#"))).toEqual({
type: "root",
content: [
m("lstinline", [
arg(null),
arg("some_code$", { openMark: "#", closeMark: "#" }),
]),
],
});
expect(
trimRenderInfo(parse("\\lstinline[language]!some_code$!"))
).toEqual({
type: "root",
content: [
m("lstinline", [
arg("language", { braces: "[]" }),
arg("some_code$", { openMark: "!", closeMark: "!" }),
]),
],
});
expect(
trimRenderInfo(parse("\\lstinline[foo %bar\n\n]{my code}"))
).toEqual({
type: "root",
content: [
m("lstinline", [
arg(
[
s("foo"),
{
type: "comment",
content: "bar",
leadingWhitespace: true,
sameline: true,
suffixParbreak: true,
},
{ type: "parbreak" },
],
{ braces: "[]" }
),
arg("my code"),
]),
],
});
expect(
trimRenderInfo(
parse("\\lstinline{code % also code\n\\still code\\\\}")
)
).toEqual({
type: "root",
content: [
m("lstinline", [
arg(null),
arg("code % also code\n\\still code\\\\"),
]),
],
});

expect(
trimRenderInfo(parse("\\mint[options]{language}#some_code$#"))
).toEqual({
type: "root",
content: [
m("mint", [
...args(["options", "language"], { braces: "[]{}" }),
arg("some_code$", { openMark: "#", closeMark: "#" }),
]),
],
});
expect(
trimRenderInfo(parse("\\mintinline[options]{language}#some_code$#"))
).toEqual({
type: "root",
content: [
m("mintinline", [
...args(["options", "language"], { braces: "[]{}" }),
arg("some_code$", { openMark: "#", closeMark: "#" }),
]),
],
});
});
});
154 changes: 154 additions & 0 deletions packages/unified-latex-util-parse/tests/parse-varbatim.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
import util from "util";
import { parse } from "../libs/parse";
import { printRaw } from "@unified-latex/unified-latex-util-print-raw";
import { parseMath } from "../libs/parse-math";
import { trimRenderInfo } from "@unified-latex/unified-latex-util-render-info";
import { SP, arg, args, m, s, env } from "@unified-latex/unified-latex-builder";

/* eslint-env jest */

// Make console.log pretty-print by default
const origLog = console.log;
console.log = (...args) => {
origLog(...args.map((x) => util.inspect(x, false, 10, true)));
};

describe("unified-latex-util-parse", () => {
it("Parses verbatim arguments from `minted` directly as strings", () => {
expect(trimRenderInfo(parse("\\lstinline{some_code$}"))).toEqual({
type: "root",
content: [
m("lstinline", args([null, "some_code$"], { braces: "[]{}" })),
],
});
expect(
trimRenderInfo(parse("\\lstinline[language]{some_code$}"))
).toEqual({
type: "root",
content: [
m(
"lstinline",
args(["language", "some_code$"], { braces: "[]{}" })
),
],
});
expect(trimRenderInfo(parse("\\lstinline#some_code$#"))).toEqual({
type: "root",
content: [
m("lstinline", [
arg(null),
arg("some_code$", { openMark: "#", closeMark: "#" }),
]),
],
});
expect(
trimRenderInfo(parse("\\lstinline[language]!some_code$!"))
).toEqual({
type: "root",
content: [
m("lstinline", [
arg("language", { braces: "[]" }),
arg("some_code$", { openMark: "!", closeMark: "!" }),
]),
],
});
expect(
trimRenderInfo(parse("\\lstinline[foo %bar\n\n]{my code}"))
).toEqual({
type: "root",
content: [
m("lstinline", [
arg(
[
s("foo"),
{
type: "comment",
content: "bar",
leadingWhitespace: true,
sameline: true,
suffixParbreak: true,
},
{ type: "parbreak" },
],
{ braces: "[]" }
),
arg("my code"),
]),
],
});
expect(
trimRenderInfo(
parse("\\lstinline{code % also code\n\\still code\\\\}")
)
).toEqual({
type: "root",
content: [
m("lstinline", [
arg(null),
arg("code % also code\n\\still code\\\\"),
]),
],
});

expect(
trimRenderInfo(parse("\\mint[options]{language}#some_code$#"))
).toEqual({
type: "root",
content: [
m("mint", [
...args(["options", "language"], { braces: "[]{}" }),
arg("some_code$", { openMark: "#", closeMark: "#" }),
]),
],
});
expect(
trimRenderInfo(parse("\\mintinline[options]{language}#some_code$#"))
).toEqual({
type: "root",
content: [
m("mintinline", [
...args(["options", "language"], { braces: "[]{}" }),
arg("some_code$", { openMark: "#", closeMark: "#" }),
]),
],
});
});

it("parses verbatim environments from `minted`", () => {
expect(
trimRenderInfo(
parse("\\begin{minted}{python}some_code$\\end{minted}")
)
).toEqual({
type: "root",
content: [
env(
"minted",
[s("some_code$")],
[
arg([], { openMark: "", closeMark: "" }),
arg("python", { braces: "{}" }),
]
),
],
});

expect(
trimRenderInfo(
parse("\\begin{minted}[foo]{python}some_code$\\end{minted}")
)
).toEqual({
type: "root",
content: [
env(
"minted",
[s("some_code$")],
[
arg("foo", { braces: "[]" }),
arg("python", { braces: "{}" }),
]
),
],
});
});
});
Loading
Loading