feat: fixed width areas

This commit is contained in:
PoiScript 2019-01-21 23:04:35 +08:00
parent 918b14de52
commit 19f7bacf55
5 changed files with 17 additions and 1 deletions

View file

@ -21,7 +21,7 @@
- [x] Blocks - [x] Blocks
- [ ] Clock, Diary Sexp and Planning - [ ] Clock, Diary Sexp and Planning
- [x] Comments - [x] Comments
- [ ] Fixed Width Areas - [x] Fixed Width Areas
- [x] Horizontal Rules - [x] Horizontal Rules
- [x] Keywords - [x] Keywords
- [ ] LaTeX Environments - [ ] LaTeX Environments

View file

@ -70,6 +70,7 @@ pub enum Element<'a> {
}, },
Rule, Rule,
Comment(&'a str), Comment(&'a str),
FixedWidth(&'a str),
List { List {
ident: usize, ident: usize,
ordered: bool, ordered: bool,
@ -178,6 +179,14 @@ impl<'a> Element<'a> {
} }
} }
if bytes[pos] == b':' && bytes.get(pos + 1).map(|&b| b == b' ').unwrap_or(false) {
let eol = src[pos..]
.find('\n')
.map(|i| i + pos + 1)
.unwrap_or_else(|| src.len());
ret!(Element::FixedWidth(&src[pos + 1..eol]), eol);
}
if bytes[pos] == b'#' && bytes.get(pos + 1).filter(|&&b| b == b'+').is_some() { if bytes[pos] == b'#' && bytes.get(pos + 1).filter(|&&b| b == b'+').is_some() {
if let Some((name, args, contents_beg, cont_end, end)) = if let Some((name, args, contents_beg, cont_end, end)) =
Block::parse(&src[pos..]) Block::parse(&src[pos..])

View file

@ -90,6 +90,9 @@ impl<W: Write> Handler<W> for HtmlHandler {
fn handle_comment(&mut self, w: &mut W, cont: &str) -> Result<()> { fn handle_comment(&mut self, w: &mut W, cont: &str) -> Result<()> {
Ok(()) Ok(())
} }
fn handle_fixed_width(&mut self, w: &mut W, cont: &str) -> Result<()> {
write!(w, "<pre>{}</pre>", cont)
}
fn handle_table_start(&mut self, w: &mut W) -> Result<()> { fn handle_table_start(&mut self, w: &mut W) -> Result<()> {
Ok(()) Ok(())
} }

View file

@ -35,6 +35,7 @@ pub trait Handler<W: Write> {
fn handle_call(&mut self, w: &mut W) -> Result<()>; fn handle_call(&mut self, w: &mut W) -> Result<()>;
fn handle_clock(&mut self, w: &mut W) -> Result<()>; fn handle_clock(&mut self, w: &mut W) -> Result<()>;
fn handle_comment(&mut self, w: &mut W, cont: &str) -> Result<()>; fn handle_comment(&mut self, w: &mut W, cont: &str) -> Result<()>;
fn handle_fixed_width(&mut self, w: &mut W, cont: &str) -> Result<()>;
fn handle_table_start(&mut self, w: &mut W) -> Result<()>; fn handle_table_start(&mut self, w: &mut W) -> Result<()>;
fn handle_table_end(&mut self, w: &mut W) -> Result<()>; fn handle_table_end(&mut self, w: &mut W) -> Result<()>;
fn handle_table_cell(&mut self, w: &mut W) -> Result<()>; fn handle_table_cell(&mut self, w: &mut W) -> Result<()>;
@ -118,6 +119,7 @@ impl<'a, W: Write, H: Handler<W>> Render<'a, W, H> {
Call => h.handle_call(w)?, Call => h.handle_call(w)?,
Clock => h.handle_clock(w)?, Clock => h.handle_clock(w)?,
Comment(c) => h.handle_comment(w, c)?, Comment(c) => h.handle_comment(w, c)?,
FixedWidth(f) => h.handle_fixed_width(w, f)?,
TableStart => h.handle_table_start(w)?, TableStart => h.handle_table_start(w)?,
TableEnd => h.handle_table_end(w)?, TableEnd => h.handle_table_end(w)?,
TableCell => h.handle_table_cell(w)?, TableCell => h.handle_table_cell(w)?,

View file

@ -122,6 +122,7 @@ pub enum Event<'a> {
Clock, Clock,
Comment(&'a str), Comment(&'a str),
FixedWidth(&'a str),
TableStart, TableStart,
TableEnd, TableEnd,
@ -259,6 +260,7 @@ impl<'a> Parser<'a> {
Element::DynBlock { name, args, .. } => Event::DynBlockBeg { name, args }, Element::DynBlock { name, args, .. } => Event::DynBlockBeg { name, args },
Element::ExampleBlock { args, cont } => Event::ExampleBlock { args, cont }, Element::ExampleBlock { args, cont } => Event::ExampleBlock { args, cont },
Element::ExportBlock { args, cont } => Event::ExportBlock { args, cont }, Element::ExportBlock { args, cont } => Event::ExportBlock { args, cont },
Element::FixedWidth(f) => Event::FixedWidth(f),
Element::FnDef { label, cont } => Event::FnDef { label, cont }, Element::FnDef { label, cont } => Event::FnDef { label, cont },
Element::Keyword { key, value } => Event::Keyword { key, value }, Element::Keyword { key, value } => Event::Keyword { key, value },
Element::List { ordered, .. } => Event::ListBeg { ordered }, Element::List { ordered, .. } => Event::ListBeg { ordered },