add links

This commit is contained in:
byte[] 2019-11-03 19:10:05 -05:00
parent fcb8919669
commit 61def278b5
2 changed files with 59 additions and 4 deletions

View file

@ -116,5 +116,61 @@ defmodule Textile.Lexer do
image_without_link
])
defparsec :image, image
# Links
{link_markup_start, link_markup_element} = markup_ending_in(string("\""))
link_contents_start =
choice([
image,
link_markup_start,
])
link_contents_element =
choice([
image,
link_markup_element
])
link_contents =
optional(link_contents_start)
|> repeat(link_contents_element)
bracketed_link_end =
string("\":")
|> unwrap_and_tag(:link_end)
|> concat(
url_ending_in(string("]"))
|> unwrap_and_tag(:link_url)
)
bracketed_link =
string("[\"")
|> unwrap_and_tag(:link_start)
|> concat(link_contents)
|> concat(bracketed_link_end)
unbracketed_link_end =
string("\":")
|> unwrap_and_tag(:link_end)
|> concat(
url_ending_in(space())
|> unwrap_and_tag(:link_url)
)
unbracketed_link =
string("\"")
|> unwrap_and_tag(:link_start)
|> concat(link_contents)
|> concat(unbracketed_link_end)
link =
choice([
bracketed_link,
unbracketed_link
])
defparsec :link, link
end

View file

@ -4,7 +4,7 @@ defmodule Textile.MarkupLexer do
# Markup tags
def markup_segment(ending_sequence) do
def markup_ending_in(ending_sequence) do
# The literal tag is special, because
# 1. It needs to capture everything inside it as a distinct token.
@ -157,7 +157,6 @@ defmodule Textile.MarkupLexer do
utf8_char([])
])
optional(markup_at_start)
|> repeat(markup_element)
{markup_at_start, markup_element}
end
end