fix: latex-environment belongs to paragraph
All checks were successful
build / build (push) Successful in 5s

wip: feat: org-element specs
This commit was merged in pull request #15.
This commit is contained in:
2026-03-08 20:06:02 -06:00
parent 2198b5f409
commit 1629efb378
11 changed files with 377 additions and 22 deletions

View File

@@ -49,3 +49,43 @@
first-paragraph-belongs-to-first-section?))
(t/is (not (-> (parse-resource "first-paragraph-under-heading.org")
first-paragraph-belongs-to-first-section?)))))
(defn walk-types [type & types]
[sut/postorder-walker #(apply sut/of-type? % type types)])
(defn- paragraph-ends-with-latex? [doc]
(let [type (-> (sp/select-first [(walk-types "paragraph")
(sp/must :children)
sp/LAST]
doc)
sut/type)]
(t/is type "latex-environment")))
(defn- paragraph-has-latex? [doc]
(t/is (sp/select-first [(walk-types "paragraph")
(sp/must :children)
sp/ALL
#(sut/of-type? % "latex-environment")]
doc)))
(defn- paragraph-has-multiple-latex? [doc]
(let [paragraphs (sp/select (walk-types "paragraph") doc)]
(t/is (= 2 (count paragraphs)))
(let [[p p] paragraphs]
(doseq [[p ts] [[p ["text" "latex-environment"
"text" "latex-environment"]]
[p ["text" "latex-environment"
"text" "latex-environment" "text"]]]]
(t/is (= ts (sp/select [(sp/must :children)
sp/ALL (sp/view sut/type)] p)))))))
(t/deftest paragraph-separation
(t/testing "paragraph ending with latex"
(-> (parse-resource "paragraph-ending-with-latex.org")
paragraph-ends-with-latex?))
(t/testing "paragraph surrounding latex"
(-> (parse-resource "paragraph-surrounding-latex.org")
paragraph-has-latex?))
(t/testing "paragraph with interleaved latex"
(-> (parse-resource "paragraph-with-multiple-latex.org")
paragraph-has-multiple-latex?)))

View File

@@ -0,0 +1,7 @@
#+title: paragraph ending with latex
here is the paragraph,
\begin{align*}
\text{and here} &
\\ & \text{is the \LaTeX}
\end{align*}

View File

@@ -0,0 +1,7 @@
#+title: paragraph surrounding latex
first part of paragraph
\begin{equation*}
\text{some \LaTeX \}:)}
\end{equation*}
last part of paragraph

View File

@@ -0,0 +1,24 @@
#+title: paragraph with multiple latex environments
* interleaved
first part of paragraph
\begin{equation*}
\text{first \LaTeX\ environment}
\end{equation*}
second part of paragraph
\begin{equation*}
\text{second \LaTeX\ environment}
\end{equation*}
* fenceposted
first fencepost
\begin{equation*}
\text{first fenceposted \LaTeX\ environment}
\end{equation*}
second fencepost
\begin{equation*}
\text{second fenceposted \LaTeX\ environment}
\end{equation*}
third fencepost