This commit was merged in pull request #17.
This commit is contained in:
@@ -232,23 +232,35 @@
|
||||
;; TODO: Construct `:contents-begin` and `:contents-end` data
|
||||
;; by spanning the children.
|
||||
first-section (merge {:type "section"
|
||||
:children first-section-nodes}
|
||||
:children (vec first-section-nodes)}
|
||||
(apply element-bounds first-section-nodes))
|
||||
new-children (concat top-level-nodes
|
||||
(list first-section)
|
||||
rest)]
|
||||
new-children (vec (concat top-level-nodes
|
||||
(list first-section)
|
||||
rest))]
|
||||
(assoc node :children new-children)))
|
||||
|
||||
(defn separated-by-explicit-paragraph-break?
|
||||
"Returh truthy if each successive pair of elements is separated by
|
||||
at least one explicit paragraph break; i.e. a blank line."
|
||||
(defn- newline-final-paragraph?
|
||||
"Is `e` a paragraph, and does it end with a newline?"
|
||||
[e]
|
||||
(and (of-type? e "paragraph")
|
||||
(some-> (-> e :position :end :column)
|
||||
(= 1))))
|
||||
|
||||
(defn consequtive-elements?
|
||||
"Returh truthy if each successive pair of elements is NOT separated
|
||||
by at least one explicit paragraph break; i.e. a blank line."
|
||||
[& elements]
|
||||
(match elements
|
||||
[e₁ e₂ & es]
|
||||
(and (< (-> e₁ :position :end :line)
|
||||
([(e₁ :guard newline-final-paragraph?) e₂ & es] :seq)
|
||||
(and (= (-> e₁ :position :end :line)
|
||||
(-> e₂ :position :start :line))
|
||||
(recur es))
|
||||
:else true))
|
||||
([e₁ e₂ & es] :seq)
|
||||
(and (= (-> e₁ :position :end :line inc)
|
||||
(-> e₂ :position :start :line))
|
||||
(recur es))
|
||||
([_] :seq) true
|
||||
([] :seq) true))
|
||||
|
||||
(defn swallow
|
||||
([predator prey]
|
||||
@@ -259,6 +271,22 @@
|
||||
([predator prey & more-prey]
|
||||
(reduce swallow predator (cons prey more-prey))))
|
||||
|
||||
(defn- paragraph-followed-by-tex? [children]
|
||||
(match children
|
||||
[(para :guard #(of-type? % "paragraph"))
|
||||
(tex :guard #(of-type? % "latex-environment"))
|
||||
& _]
|
||||
(consequtive-elements? para tex)
|
||||
:else false))
|
||||
|
||||
(defn- paragraph-followed-by-paragraph? [children]
|
||||
(match children
|
||||
[(para₁ :guard #(of-type? % "paragraph"))
|
||||
(para₂ :guard #(of-type? % "paragraph"))
|
||||
& _]
|
||||
(consequtive-elements? para₁ para₂)
|
||||
:else false))
|
||||
|
||||
(defn gather-latex-paragraphs [node]
|
||||
(->> node
|
||||
(sp/transform
|
||||
@@ -271,16 +299,14 @@
|
||||
;; If there are no blank lines separating the paragraph
|
||||
;; from the LaTeX environment, the LaTeX environment
|
||||
;; shall become a child of the paragraph.
|
||||
([(para :guard #(of-type? % "paragraph"))
|
||||
(tex :guard #(of-type? % "latex-environment"))
|
||||
& rest]
|
||||
:guard #(apply separated-by-explicit-paragraph-break? %))
|
||||
([para tex & rest] :guard paragraph-followed-by-tex?)
|
||||
(recur acc (vec (cons (swallow para tex) rest)))
|
||||
;; CASE:
|
||||
([(para₁ :guard #(of-type? % "paragraph"))
|
||||
(para₂ :guard #(of-type? % "paragraph"))
|
||||
& rest]
|
||||
:guard #(apply separated-by-explicit-paragraph-break? %))
|
||||
;; CASE: Similar to the paragraph-followed-by-tex case,
|
||||
;; but instead of swallowing the entire second element,
|
||||
;; we swallow the /children/ of the second element,
|
||||
;; since paragraphs cannot be nested.
|
||||
([para₁ para₂ & rest]
|
||||
:guard paragraph-followed-by-paragraph?)
|
||||
(recur acc (vec (cons (apply swallow para₁ (:children para₂))
|
||||
rest)))
|
||||
;; CASE: Irrelevant or empty!
|
||||
|
||||
@@ -9,9 +9,7 @@
|
||||
[net.deertopia.doerg.html :as doerg-html]
|
||||
[hiccup2.core :as hiccup]
|
||||
[clojure.pprint]
|
||||
;; #_
|
||||
[net.deertopia.doerg.tex :as tex]
|
||||
;; [net.deertopia.doerg.tex.native :as tex-native]
|
||||
[net.deertopia.doerg.tex.temml :as tex-temml]
|
||||
[clojure.zip :as z]
|
||||
[babashka.fs :as fs]))
|
||||
|
||||
Reference in New Issue
Block a user