logseq / mldoc

Another Emacs Org-mode and Markdown parser.
GNU Affero General Public License v3.0
236 stars 21 forks source link

feat: parsing return inline_type position info #69

Closed RCmerci closed 3 years ago

RCmerci commented 3 years ago
frontend.format.mldoc> (inline->edn "> [[a[[b]]]] *c*" (default-config :markdown false false true))
[[["Plain" "> "] {:start_pos 0, :end_pos 2}]
 [["Nested_link"
   [{:content "[[a[[b]]]]",
     :children
     [["Label" "a"]
      ["Nested_link"
       [{:content "[[b]]", :children [["Label" "b"]]}
        {:start_pos 5, :end_pos 10}]]]}
    {:start_pos 2, :end_pos 12}]]
  {:start_pos 2, :end_pos 12}]
 [["Plain" " "] {:start_pos 12, :end_pos 13}]
 [["Emphasis" [["Italic"] [["Plain" "c"]]]]
  {:start_pos 13, :end_pos 16}]]

Currently, inline-type pos is just relative positions to its block-type when using mldoc/parseJson. Using mldoc/inline-edn only parsing inline-type to get absolute pos.

A little troublesome to compute the absolute pos, because there are several cases(e.g lib/syntax/block.ml:159) that parse modified contents (e.g. trim prefix indents or spaces) then Angstrom.pos can't get correct pos .

tiensonqin commented 3 years ago

Yes, it could be an issue if the editing block content has preceding spaces or newlines. Let's merge this now.