-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(converter): support figure and tabular environments (#154)
* dev: clean code * dev: more convert functions * dev: update itemcmd * dev: minor improvements * test(convert): refactor tests * dev: add converter.rs * fix: make ci happy * dev: add convert_env * dev: simplify \label for env * feat: add quote and abstract envs * dev: support caption for figure * fix: fix figure env bug * test: use assert_snapshot * test: update tests * fix: make insta test happy * fix: make ci happy * fix: fix bug of commands * feat: add support for \includegraphics * feat: add convert_env_figure * feat: support basic tabular * fix: make ci happy * feat: support \toprule, \midrule, and \bottomrule * dev: merge main branch * dev: update * fix: fix bug of glob env * fix: fix bug of Glob * fix: add pattern for Glob * docs: update README
- Loading branch information
Showing
19 changed files
with
921 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
use super::prelude::*; | ||
|
||
#[test] | ||
fn figure() { | ||
assert_debug_snapshot!(parse(r###" | ||
\begin{figure}[ht] | ||
\centering | ||
\includegraphics[width=0.5\textwidth]{example-image} | ||
\caption{This is an example image.} | ||
\label{fig:example} | ||
\end{figure} | ||
"###), @r###" | ||
root | ||
|br'("\n") | ||
|space'(" ") | ||
|env | ||
||begin | ||
|||sym'("figure") | ||
|||args | ||
||||bracket | ||
|||||lbracket'("[") | ||
|||||text(word'("ht")) | ||
|||||rbracket'("]") | ||
||br'("\n") | ||
||space'(" ") | ||
||cmd(cmd-name("\\centering")) | ||
||br'("\n") | ||
||space'(" ") | ||
||cmd | ||
|||cmd-name("\\includegraphics") | ||
|||args | ||
||||bracket | ||
|||||lbracket'("[") | ||
|||||text(word'("width=0.5")) | ||
|||||cmd(cmd-name("\\textwidth")) | ||
|||||rbracket'("]") | ||
|||args | ||
||||curly | ||
|||||lbrace'("{") | ||
|||||text(word'("example-image")) | ||
|||||rbrace'("}") | ||
||br'("\n") | ||
||space'(" ") | ||
||cmd | ||
|||cmd-name("\\caption") | ||
|||args | ||
||||curly | ||
|||||lbrace'("{") | ||
|||||text(word'("This"),space'(" "),word'("is"),space'(" "),word'("an"),space'(" "),word'("example"),space'(" "),word'("image.")) | ||
|||||rbrace'("}") | ||
||br'("\n") | ||
||space'(" ") | ||
||cmd | ||
|||cmd-name("\\label") | ||
|||args | ||
||||curly | ||
|||||lbrace'("{") | ||
|||||text(word'("fig:example")) | ||
|||||rbrace'("}") | ||
||br'("\n") | ||
||space'(" ") | ||
||end(sym'("figure")) | ||
|br'("\n") | ||
|space'(" ") | ||
"###); | ||
} | ||
|
||
#[test] | ||
fn table() { | ||
assert_debug_snapshot!(parse(r###" | ||
\begin{table}[ht] | ||
\centering | ||
\begin{tabular}{|c|c|} | ||
\hline | ||
\textbf{Name} & \textbf{Age} \\ | ||
\hline | ||
John & 25 \\ | ||
Jane & 22 \\ | ||
\hline | ||
\end{tabular} | ||
\caption{This is an example table.} | ||
\label{tab:example} | ||
\end{table} | ||
"###), @r###" | ||
root | ||
|br'("\n") | ||
|space'(" ") | ||
|env | ||
||begin | ||
|||sym'("table") | ||
|||args | ||
||||bracket | ||
|||||lbracket'("[") | ||
|||||text(word'("ht")) | ||
|||||rbracket'("]") | ||
||br'("\n") | ||
||space'(" ") | ||
||cmd(cmd-name("\\centering")) | ||
||br'("\n") | ||
||space'(" ") | ||
||env | ||
|||begin | ||
||||sym'("tabular") | ||
||||args | ||
|||||curly | ||
||||||lbrace'("{") | ||
||||||text(word'("|c|c|")) | ||
||||||rbrace'("}") | ||
|||br'("\n") | ||
|||space'(" ") | ||
|||cmd(cmd-name("\\hline")) | ||
|||br'("\n") | ||
|||space'(" ") | ||
|||cmd | ||
||||cmd-name("\\textbf") | ||
||||args | ||
|||||curly | ||
||||||lbrace'("{") | ||
||||||text(word'("Name")) | ||
||||||rbrace'("}") | ||
|||space'(" ") | ||
|||ampersand'("&") | ||
|||space'(" ") | ||
|||cmd | ||
||||cmd-name("\\textbf") | ||
||||args | ||
|||||curly | ||
||||||lbrace'("{") | ||
||||||text(word'("Age")) | ||
||||||rbrace'("}") | ||
|||space'(" ") | ||
|||newline("\\\\") | ||
|||br'("\n") | ||
|||space'(" ") | ||
|||cmd(cmd-name("\\hline")) | ||
|||br'("\n") | ||
|||space'(" ") | ||
|||text(word'("John"),space'(" ")) | ||
|||ampersand'("&") | ||
|||space'(" ") | ||
|||text(word'("25"),space'(" ")) | ||
|||newline("\\\\") | ||
|||br'("\n") | ||
|||space'(" ") | ||
|||text(word'("Jane"),space'(" ")) | ||
|||ampersand'("&") | ||
|||space'(" ") | ||
|||text(word'("22"),space'(" ")) | ||
|||newline("\\\\") | ||
|||br'("\n") | ||
|||space'(" ") | ||
|||cmd(cmd-name("\\hline")) | ||
|||br'("\n") | ||
|||space'(" ") | ||
|||end(sym'("tabular")) | ||
||br'("\n") | ||
||space'(" ") | ||
||cmd | ||
|||cmd-name("\\caption") | ||
|||args | ||
||||curly | ||
|||||lbrace'("{") | ||
|||||text(word'("This"),space'(" "),word'("is"),space'(" "),word'("an"),space'(" "),word'("example"),space'(" "),word'("table.")) | ||
|||||rbrace'("}") | ||
||br'("\n") | ||
||space'(" ") | ||
||cmd | ||
|||cmd-name("\\label") | ||
|||args | ||
||||curly | ||
|||||lbrace'("{") | ||
|||||text(word'("tab:example")) | ||
|||||rbrace'("}") | ||
||br'("\n") | ||
||space'(" ") | ||
||end(sym'("table")) | ||
|br'("\n") | ||
|space'(" ") | ||
"###); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
use super::prelude::*; | ||
|
||
#[test] | ||
fn tabular() { | ||
assert_debug_snapshot!(parse(r###" | ||
\begin{tabular}{|c|c|} | ||
\hline | ||
\textbf{Name} & \textbf{Age} \\ | ||
\hline | ||
John & 25 \\ | ||
Jane & 22 \\ | ||
\hline | ||
\end{tabular} | ||
"###), @r###" | ||
root | ||
|br'("\n") | ||
|space'(" ") | ||
|env | ||
||begin | ||
|||sym'("tabular") | ||
|||args | ||
||||curly | ||
|||||lbrace'("{") | ||
|||||text(word'("|c|c|")) | ||
|||||rbrace'("}") | ||
||br'("\n") | ||
||space'(" ") | ||
||cmd(cmd-name("\\hline")) | ||
||br'("\n") | ||
||space'(" ") | ||
||cmd | ||
|||cmd-name("\\textbf") | ||
|||args | ||
||||curly | ||
|||||lbrace'("{") | ||
|||||text(word'("Name")) | ||
|||||rbrace'("}") | ||
||space'(" ") | ||
||ampersand'("&") | ||
||space'(" ") | ||
||cmd | ||
|||cmd-name("\\textbf") | ||
|||args | ||
||||curly | ||
|||||lbrace'("{") | ||
|||||text(word'("Age")) | ||
|||||rbrace'("}") | ||
||space'(" ") | ||
||newline("\\\\") | ||
||br'("\n") | ||
||space'(" ") | ||
||cmd(cmd-name("\\hline")) | ||
||br'("\n") | ||
||space'(" ") | ||
||text(word'("John"),space'(" ")) | ||
||ampersand'("&") | ||
||space'(" ") | ||
||text(word'("25"),space'(" ")) | ||
||newline("\\\\") | ||
||br'("\n") | ||
||space'(" ") | ||
||text(word'("Jane"),space'(" ")) | ||
||ampersand'("&") | ||
||space'(" ") | ||
||text(word'("22"),space'(" ")) | ||
||newline("\\\\") | ||
||br'("\n") | ||
||space'(" ") | ||
||cmd(cmd-name("\\hline")) | ||
||br'("\n") | ||
||space'(" ") | ||
||end(sym'("tabular")) | ||
|br'("\n") | ||
|space'(" ") | ||
"###); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.