Skip to content

Commit

Permalink
fix: cleanup ast for links
Browse files Browse the repository at this point in the history
  • Loading branch information
mscharley committed May 31, 2024
1 parent ceadc0a commit 171b6a5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion gleam.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# https://gleam.run/writing-gleam/gleam-toml/.

name = "commonmark"
version = "0.1.0"
version = "0.1.1"
description = "CommonMark implementation for Gleam, for the BEAM or JS"
licenses = ["MIT"]
links = [
Expand Down
14 changes: 9 additions & 5 deletions src/commonmark/ast.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ pub type InlineNode {
Emphasis(contents: List(InlineNode), marker: EmphasisMarker)
StrongEmphasis(contents: List(InlineNode), marker: EmphasisMarker)
StrikeThrough(contents: List(InlineNode))
Link(title: List(InlineNode), href: String)
ReferenceLink(title: List(InlineNode), ref: String)
Image(title: String, href: String)
Link(contents: List(InlineNode), title: Option(String), href: String)
ReferenceLink(content: List(InlineNode), ref: String)
Image(title: Option(String), href: String)
UriAutolink(href: String)
EmailAutolink(href: String)
HtmlInline(html: String)
Expand Down Expand Up @@ -70,15 +70,19 @@ pub type BlockNode {
Heading(level: Int, contents: List(InlineNode))
CodeBlock(info: Option(String), full_info: Option(String), contents: String)
HtmlBlock(html: String)
LinkReference(name: String, href: String)
Paragraph(contents: List(InlineNode))
BlockQuote(contents: List(BlockNode))
OrderedList(contents: List(ListItem), start: Int, marker: OrderedListMarker)
UnorderedList(contents: List(ListItem), marker: UnorderedListMarker)
}

/// A reference used with ReferenceLink nodes
pub type Reference {
Reference(href: String, title: Option(String))
}

/// Documents contain all the information necessary to render a document, both structural and
/// metadata.
pub type Document {
Document(blocks: List(BlockNode), references: Dict(String, String))
Document(blocks: List(BlockNode), references: Dict(String, Reference))
}
3 changes: 1 addition & 2 deletions src/commonmark/internal/html.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub fn inline_to_html(inline: ast.InlineNode) -> String {
ast.HtmlInline(html) -> html
ast.Image(_, _) -> "Image"
ast.ReferenceLink(_, _) -> "Link"
ast.Link(_, _) -> "Link"
ast.Link(_, _, _) -> "Link"
ast.NamedEntity("amp", _) -> "&"
ast.NamedEntity(_, cp) -> string.from_utf_codepoints(cp)
ast.NumericCharacterReference(cp, _) -> string.from_utf_codepoints([cp])
Expand All @@ -58,7 +58,6 @@ pub fn inline_to_html(inline: ast.InlineNode) -> String {

pub fn block_to_html(block: ast.BlockNode) -> String {
case block {
ast.LinkReference(_, _) -> ""
ast.CodeBlock(None, _, contents) ->
"<pre><code>" <> { contents |> sanitize_plain_text } <> "</code></pre>\n"
ast.CodeBlock(Some(info), _, contents) ->
Expand Down

0 comments on commit 171b6a5

Please sign in to comment.