It seems to be working now that I've integrated links.
This commit is contained in:
parent
5b306729f5
commit
cc41074563
@ -81,7 +81,7 @@ pub struct Bold<'a> {
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Link<'a> {
|
||||
contents: &'a str,
|
||||
pub contents: &'a str,
|
||||
}
|
||||
|
||||
pub fn line_break(input: &str) -> Res<&str, LineBreak> {
|
||||
|
@ -10,10 +10,13 @@ use super::nom_context::OrgModeContextTree;
|
||||
use super::text::bold_end;
|
||||
use super::text::bold_start;
|
||||
use super::text::line_break;
|
||||
use super::text::link_end;
|
||||
use super::text::link_start;
|
||||
use super::text::space;
|
||||
use super::text::span;
|
||||
use super::text::symbol;
|
||||
use super::text::Bold;
|
||||
use super::text::Link;
|
||||
use super::text::Res;
|
||||
use super::text::TextElement;
|
||||
use nom::branch::alt;
|
||||
@ -33,9 +36,11 @@ fn flat_text_element<'s, 'r>(
|
||||
not(|i| context.match_fail(i))(i)?;
|
||||
|
||||
let bold_matcher = parser_with_context!(flat_bold)(context);
|
||||
let link_matcher = parser_with_context!(flat_link)(context);
|
||||
|
||||
alt((
|
||||
bold_matcher,
|
||||
link_matcher,
|
||||
map(span, TextElement::Span),
|
||||
map(symbol("*"), TextElement::Symbol),
|
||||
map(symbol("["), TextElement::Symbol),
|
||||
@ -60,6 +65,21 @@ fn flat_bold<'s, 'r>(i: &'s str, context: &'r OrgModeContext<'r>) -> Res<&'s str
|
||||
Ok((remaining, ret))
|
||||
}
|
||||
|
||||
fn recognize_link_end(input: &str) -> Res<&str, &str> {
|
||||
recognize(link_end)(input)
|
||||
}
|
||||
|
||||
fn flat_link<'s, 'r>(i: &'s str, context: &'r OrgModeContext<'r>) -> Res<&'s str, TextElement<'s>> {
|
||||
let new_context = context.with_additional_fail_matcher(&recognize_link_end);
|
||||
let text_element_parser = parser_with_context!(flat_text_element)(&new_context);
|
||||
let (remaining, captured) = recognize(tuple((
|
||||
link_start,
|
||||
many_till(text_element_parser, link_end),
|
||||
)))(i)?;
|
||||
let ret = TextElement::Link(Link { contents: captured });
|
||||
Ok((remaining, ret))
|
||||
}
|
||||
|
||||
pub fn paragraph<'s, 'r>(
|
||||
i: &'s str,
|
||||
context: &'r OrgModeContext<'r>,
|
||||
|
Loading…
x
Reference in New Issue
Block a user