Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add core Footnote and BlockQuote BlockType #11

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion FDOM.Core/Common.fs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ module DOM =
and FootnoteBlock =
{ Name: string
Paragraphs: ParagraphBlock }

and BlockQuoteBlock =
{
Content: BlockContent list
}

and BlockContent =
| Header of HeaderBlock
Expand All @@ -100,6 +105,7 @@ module DOM =
| Image of ImageBlock
| Table of TableBlock
| FootNote of FootnoteBlock
| BlockQuote of BlockQuoteBlock

member bc.GetRawText() =
match bc with
Expand Down Expand Up @@ -255,7 +261,6 @@ module DOM =
let createSpan style text =
InlineContent.Span { Style = style; Content = text }


let createLink style text url =
InlineContent.Link
{ Style = style
Expand Down
15 changes: 12 additions & 3 deletions FDOM.Core/Parsing.fs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ module BlockParser =
| Image of Text: string
| Table of Text: string
| InlineMetadata of Text: string
| Footnote of Text: string
| BlockQuote of Text: string
| Empty

[<RequireQualifiedAccess>]
Expand Down Expand Up @@ -120,7 +122,7 @@ module BlockParser =
let tryParseParagraph (formatter: Line list -> string) (input: Input) curr =
match input.TryGetLine curr with
| None -> Error()
| Some l when l.Type <> LineType.Text -> Error()
| Some l when l.Type <> LineType.Text && l.Type <> LineType.IndentedText -> Error()
| _ ->
// This looks for text or indented text because paragraph lines could start with a space.
let lines, next = input.TryGetUntilNotTypesOrEnd(curr, [ LineType.Text; LineType.IndentedText ])
Expand Down Expand Up @@ -219,6 +221,11 @@ module BlockParser =
match input.TryGetLine curr with
| None -> Error()
| Some l when l.Type <> LineType.Footnote -> Error()
| Some l ->



Ok (BlockToken.Header)

let tryParseBlockQuote (input: Input) curr =

Expand Down Expand Up @@ -264,6 +271,8 @@ module BlockParser =

handler ([], 0)

open BlockParser

/// The inline parse takes block tokens and creates a DOM.
module InlineParser =

Expand Down Expand Up @@ -477,7 +486,6 @@ module Processing =
(Style.references [ lang |> Option.map (fun l -> $"language-{l}") |> Option.defaultValue "" ])
[ DOM.InlineContent.Text { Content = value } ]


let createImageBlock (value: string) =
// Split the image into parts.

Expand Down Expand Up @@ -505,7 +513,6 @@ module Processing =

img Style.none url title altText height width


let createListItem (value: string) =
li Style.none (InlineParser.parseInlineContent value)

Expand Down Expand Up @@ -636,6 +643,8 @@ module Processing =
(p Style.none [ DOM.InlineContent.Text { Content = "" } ], remainingBlocks.Tail)
| BlockParser.BlockToken.Empty _ ->
(p Style.none [ DOM.InlineContent.Text { Content = "" } ], remainingBlocks.Tail)
| BlockToken.Footnote text -> failwith "todo"
| BlockToken.BlockQuote text -> failwith "todo"

handler (append processedBlocks newBlock, newRemainingBlocks)

Expand Down