Skip to content

Commit c0d196b

Browse files
Update markdown parser for ## headers
1 parent dfc6cba commit c0d196b

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

src/markdown.clj

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,26 +96,30 @@
9696
(from-range (nth node 1) content)
9797
(seq node)))
9898

99+
(defn section-content [content node]
100+
(from-range (nth node 1) content))
101+
99102
(defn h1-prompt-content [content node]
100103
(merge
101104
(-> node (nth 2) (nth 3) (nth 1) (from-range content) (parse-h1))
102-
;; TODO merge a description and filter node content
103105
(if (some section? node)
106+
;; prompt is broken up with real sections
104107
(merge
105108
{:content (->> node
106-
(filter section?)
109+
(filter list?)
107110
(filter (complement (partial description-section? content)))
108111
#_(filter (complement atx-heading-section?))
109-
(map (partial section-content-without-headings content))
112+
(map (partial section-content content))
110113
(apply str)
111114
(string/trim))}
112-
(when-let [description (->> node
113-
(filter section?)
114-
(filter (partial description-section? content))
115-
first
116-
(section-content-without-headings content)
117-
(string/trim))]
115+
(when-let [description (some->> node
116+
(filter section?)
117+
(filter (partial description-section? content))
118+
first
119+
(section-content-without-headings content)
120+
(string/trim))]
118121
{:description description}))
122+
;; the contene is just one big section with no description
119123
{:content (string/trim (section-content-without-headings content node))})))
120124

121125
(def heading-1-loc->top-level-section-node (comp zip/node zip/up zip/up))
@@ -196,8 +200,8 @@
196200
(some (fn [loc] (when (section? (zip/node loc)) loc))))]
197201
(when-let [first-code-block
198202
(->>
199-
(iterate zip/right (zip/down first-section))
200-
(some (fn [loc] (when (fenced-code-block? (zip/node loc)) loc))))]
203+
(iterate zip/right (zip/down first-section))
204+
(some (fn [loc] (when (fenced-code-block? (zip/node loc)) loc))))]
201205
first-code-block))]
202206
(->
203207
(from-range (-> loc zip/node (nth 5) (nth 1)) content)

0 commit comments

Comments
 (0)