Skip to content

Commit

Permalink
Add Paragraph_Sep
Browse files Browse the repository at this point in the history
  • Loading branch information
tiensonqin committed May 9, 2020
1 parent 4164ced commit a788802
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 11 deletions.
2 changes: 1 addition & 1 deletion bin/main.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
open Mldoc_org
open Mldoc_org.Parser
open Mldoc_org.Config
open Mldoc_org.Conf
open Lwt
open Cmdliner

Expand Down
4 changes: 2 additions & 2 deletions js/lib.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
open Mldoc_org
open Mldoc_org.Parser
open Mldoc_org.Config
open Mldoc_org.Conf

let ast_to_json ast =
Type.blocks_to_yojson ast |> Yojson.Safe.to_string
Expand All @@ -16,7 +16,7 @@ let _ =
method parseJson input config_json =
let config_json = Js.to_string config_json in
let config_json = Yojson.Safe.from_string config_json in
match Config.of_yojson config_json with
match Conf.of_yojson config_json with
| Ok config -> begin
let str = Js.to_string input in
parse config str |> ast_to_json |> Js.string
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/export/exporter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module type Exporter = sig

val default_filename : string -> string

val export: Config.t -> Document.t -> out_channel -> unit
val export: Conf.t -> Document.t -> out_channel -> unit
end

type exporter = (module Exporter)
Expand Down
4 changes: 2 additions & 2 deletions lib/export/html.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ open Type
open Inline
open Document
open Timestamp
open Config
open Conf

(* taken from mlorg *)

Expand Down Expand Up @@ -425,7 +425,7 @@ module HtmlExporter = struct
* [Xml.data s; Xml.raw "<br />"; subtitle] in *)

let blocks = blocks config doc.blocks in
let blocks = if Config.(config.toc) then ((toc config doc.toc) :: blocks) else blocks in
let blocks = if Conf.(config.toc) then ((toc config doc.toc) :: blocks) else blocks in
let body = [Xml.raw ("<!-- directives: " ^ (directives_to_string doc.directives) ^ " -->\n");
Xml.block "div" ~attr:[("id", "content")] blocks] in
Xml.output_xhtml output body
Expand Down
2 changes: 1 addition & 1 deletion lib/mldoc_org.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Document = Document
module Block = Block
module Inline = Inline
module Exporters = Exporter.Exporters
module Config = Config
module Conf = Conf
module Exporter = Exporter
module Timestamp = Timestamp
module Parser = Org_parser
Expand Down
6 changes: 4 additions & 2 deletions lib/org_parser.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ let list_content_parsers config =
; Hr.parse
; Block.results
; Comment.parse
; Paragraph.parse config [ Table.parse
; Paragraph.parse config [ Paragraph.sep
; Table.parse
; Block.parse config
; Block.results
; Latex_env.parse
Expand All @@ -18,7 +19,8 @@ let list_content_parsers config =

(* Orders care *)
let interrupt_parsers config =
[ Heading.parse
[ Paragraph.sep
; Heading.parse
; Table.parse
; Lists.parse (list_content_parsers config)
; Block.parse config
Expand Down
4 changes: 3 additions & 1 deletion lib/syntax/inline.ml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ and t =
Emphasis of emphasis
| Break_Line
| Hard_Break_Line
| Paragraph_Sep
| Verbatim of string
| Code of string
| Spaces of string
Expand Down Expand Up @@ -156,7 +157,8 @@ let verbatim =
let code = between '~' >>= fun s -> return (Code s) <?> "Inline code"

(* TODO: optimization *)
let plain_delims = ['*'; '_'; '/'; '\\'; '+'; '~'; '='; '['; '<'; '{'; '$'; '^';]
let plain_delims = ['*'; '_'; '/'; '\\'; '+'; '~'; '='; '['; '<'; '{'; '$'; '^'; '\n'; '\r'; '(']
(* replace list with a *)
let in_plain_delims c =
List.exists (fun d -> c = d) plain_delims

Expand Down
10 changes: 9 additions & 1 deletion lib/syntax/paragraph.ml
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
open Angstrom
open Parsers
open Type
open Config
open Conf

(* inline and footnotes *)

let sep =
eols >>= fun s ->
print_int (String.length s);
if String.length s >= 2 then
return [Paragraph_Sep]
else
fail "only 1 eol"

let parse_paragraph config interrupt_parsers lines =
let open List in
let inline_parse () =
Expand Down
1 change: 1 addition & 0 deletions lib/syntax/type.ml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ and code_block =

and t =
Paragraph of Inline.t list (** A paragraph containing only inline text *)
| Paragraph_Sep
| Heading of heading (** A heading *)
| List of list_item list (** A list [item] *)
| Directive of string * string (** A directive [name, value] *)
Expand Down

0 comments on commit a788802

Please sign in to comment.