Browse Source

fix: allow no blank line after front matter

Yukun Guo 5 years ago
parent
commit
2d8fd7072b
1 changed files with 9 additions and 2 deletions
  1. 9 2
      src/main/frontend/db.cljs

+ 9 - 2
src/main/frontend/db.cljs

@@ -1180,8 +1180,15 @@
              (string/join "\n"))
 
         :markdown
-        (str (subs content 0 (string/last-index-of content "---\n\n"))
-             "---\n\n")
+        (let [[m leading-spaces first-dashes] (re-find #"(\s*)(---\n)" content)]
+          (if m
+            (let [begin (count leading-spaces)
+                  begin-inner (+ begin (count first-dashes))
+                  second-dashes "\n---\n"
+                  end-inner (string/index-of content second-dashes begin-inner)
+                  end (if end-inner (+ end-inner (count second-dashes)) begin)]
+              (subs content begin end))
+            ""))
 
         content))))