refactor(export): minor refactor
This commit is contained in:
parent
ab377b2cc5
commit
dd638d0d4a
|
@ -3,7 +3,7 @@ use std::io::{Error, Write};
|
||||||
|
|
||||||
use jetscii::{bytes, BytesConst};
|
use jetscii::{bytes, BytesConst};
|
||||||
|
|
||||||
use crate::elements::Element;
|
use crate::elements::{Element, Timestamp};
|
||||||
use crate::export::write_datetime;
|
use crate::export::write_datetime;
|
||||||
|
|
||||||
/// A wrapper for escaping sensitive characters in html.
|
/// A wrapper for escaping sensitive characters in html.
|
||||||
|
@ -51,44 +51,42 @@ impl<S: AsRef<str>> fmt::Display for HtmlEscape<S> {
|
||||||
|
|
||||||
pub trait HtmlHandler<E: From<Error>>: Default {
|
pub trait HtmlHandler<E: From<Error>>: Default {
|
||||||
fn start<W: Write>(&mut self, mut w: W, element: &Element) -> Result<(), E> {
|
fn start<W: Write>(&mut self, mut w: W, element: &Element) -> Result<(), E> {
|
||||||
use Element::*;
|
|
||||||
|
|
||||||
match element {
|
match element {
|
||||||
// container elements
|
// container elements
|
||||||
SpecialBlock(_) => (),
|
Element::SpecialBlock(_) => (),
|
||||||
QuoteBlock(_) => write!(w, "<blockquote>")?,
|
Element::QuoteBlock(_) => write!(w, "<blockquote>")?,
|
||||||
CenterBlock(_) => write!(w, "<div class=\"center\">")?,
|
Element::CenterBlock(_) => write!(w, "<div class=\"center\">")?,
|
||||||
VerseBlock(_) => write!(w, "<p class=\"verse\">")?,
|
Element::VerseBlock(_) => write!(w, "<p class=\"verse\">")?,
|
||||||
Bold => write!(w, "<b>")?,
|
Element::Bold => write!(w, "<b>")?,
|
||||||
Document { .. } => write!(w, "<main>")?,
|
Element::Document { .. } => write!(w, "<main>")?,
|
||||||
DynBlock(_dyn_block) => (),
|
Element::DynBlock(_dyn_block) => (),
|
||||||
Headline { .. } => (),
|
Element::Headline { .. } => (),
|
||||||
List(list) => {
|
Element::List(list) => {
|
||||||
if list.ordered {
|
if list.ordered {
|
||||||
write!(w, "<ol>")?;
|
write!(w, "<ol>")?;
|
||||||
} else {
|
} else {
|
||||||
write!(w, "<ul>")?;
|
write!(w, "<ul>")?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Italic => write!(w, "<i>")?,
|
Element::Italic => write!(w, "<i>")?,
|
||||||
ListItem(_) => write!(w, "<li>")?,
|
Element::ListItem(_) => write!(w, "<li>")?,
|
||||||
Paragraph { .. } => write!(w, "<p>")?,
|
Element::Paragraph { .. } => write!(w, "<p>")?,
|
||||||
Section => write!(w, "<section>")?,
|
Element::Section => write!(w, "<section>")?,
|
||||||
Strike => write!(w, "<s>")?,
|
Element::Strike => write!(w, "<s>")?,
|
||||||
Underline => write!(w, "<u>")?,
|
Element::Underline => write!(w, "<u>")?,
|
||||||
// non-container elements
|
// non-container elements
|
||||||
CommentBlock(_) => (),
|
Element::CommentBlock(_) => (),
|
||||||
ExampleBlock(block) => write!(
|
Element::ExampleBlock(block) => write!(
|
||||||
w,
|
w,
|
||||||
"<pre class=\"example\">{}</pre>",
|
"<pre class=\"example\">{}</pre>",
|
||||||
HtmlEscape(&block.contents)
|
HtmlEscape(&block.contents)
|
||||||
)?,
|
)?,
|
||||||
ExportBlock(block) => {
|
Element::ExportBlock(block) => {
|
||||||
if block.data.eq_ignore_ascii_case("HTML") {
|
if block.data.eq_ignore_ascii_case("HTML") {
|
||||||
write!(w, "{}", block.contents)?
|
write!(w, "{}", block.contents)?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SourceBlock(block) => {
|
Element::SourceBlock(block) => {
|
||||||
if block.language.is_empty() {
|
if block.language.is_empty() {
|
||||||
write!(
|
write!(
|
||||||
w,
|
w,
|
||||||
|
@ -104,34 +102,32 @@ pub trait HtmlHandler<E: From<Error>>: Default {
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BabelCall(_) => (),
|
Element::BabelCall(_) => (),
|
||||||
InlineSrc(inline_src) => write!(
|
Element::InlineSrc(inline_src) => write!(
|
||||||
w,
|
w,
|
||||||
"<code class=\"src src-{}\">{}</code>",
|
"<code class=\"src src-{}\">{}</code>",
|
||||||
inline_src.lang,
|
inline_src.lang,
|
||||||
HtmlEscape(&inline_src.body)
|
HtmlEscape(&inline_src.body)
|
||||||
)?,
|
)?,
|
||||||
Code { value } => write!(w, "<code>{}</code>", HtmlEscape(value))?,
|
Element::Code { value } => write!(w, "<code>{}</code>", HtmlEscape(value))?,
|
||||||
FnRef(_fn_ref) => (),
|
Element::FnRef(_fn_ref) => (),
|
||||||
InlineCall(_) => (),
|
Element::InlineCall(_) => (),
|
||||||
Link(link) => write!(
|
Element::Link(link) => write!(
|
||||||
w,
|
w,
|
||||||
"<a href=\"{}\">{}</a>",
|
"<a href=\"{}\">{}</a>",
|
||||||
HtmlEscape(&link.path),
|
HtmlEscape(&link.path),
|
||||||
HtmlEscape(link.desc.as_ref().unwrap_or(&link.path)),
|
HtmlEscape(link.desc.as_ref().unwrap_or(&link.path)),
|
||||||
)?,
|
)?,
|
||||||
Macros(_macros) => (),
|
Element::Macros(_macros) => (),
|
||||||
RadioTarget => (),
|
Element::RadioTarget => (),
|
||||||
Snippet(snippet) => {
|
Element::Snippet(snippet) => {
|
||||||
if snippet.name.eq_ignore_ascii_case("HTML") {
|
if snippet.name.eq_ignore_ascii_case("HTML") {
|
||||||
write!(w, "{}", snippet.value)?;
|
write!(w, "{}", snippet.value)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Target(_target) => (),
|
Element::Target(_target) => (),
|
||||||
Text { value } => write!(w, "{}", HtmlEscape(value))?,
|
Element::Text { value } => write!(w, "{}", HtmlEscape(value))?,
|
||||||
Timestamp(timestamp) => {
|
Element::Timestamp(timestamp) => {
|
||||||
use crate::elements::Timestamp;
|
|
||||||
|
|
||||||
write!(
|
write!(
|
||||||
&mut w,
|
&mut w,
|
||||||
"<span class=\"timestamp-wrapper\"><span class=\"timestamp\">"
|
"<span class=\"timestamp-wrapper\"><span class=\"timestamp\">"
|
||||||
|
@ -159,57 +155,60 @@ pub trait HtmlHandler<E: From<Error>>: Default {
|
||||||
|
|
||||||
write!(&mut w, "</span></span>")?;
|
write!(&mut w, "</span></span>")?;
|
||||||
}
|
}
|
||||||
Verbatim { value } => write!(&mut w, "<code>{}</code>", HtmlEscape(value))?,
|
Element::Verbatim { value } => write!(&mut w, "<code>{}</code>", HtmlEscape(value))?,
|
||||||
FnDef(_fn_def) => (),
|
Element::FnDef(_fn_def) => (),
|
||||||
Clock(_clock) => (),
|
Element::Clock(_clock) => (),
|
||||||
Comment(_) => (),
|
Element::Comment(_) => (),
|
||||||
FixedWidth(fixed_width) => write!(
|
Element::FixedWidth(fixed_width) => write!(
|
||||||
w,
|
w,
|
||||||
"<pre class=\"example\">{}</pre>",
|
"<pre class=\"example\">{}</pre>",
|
||||||
HtmlEscape(&fixed_width.value)
|
HtmlEscape(&fixed_width.value)
|
||||||
)?,
|
)?,
|
||||||
Keyword(_keyword) => (),
|
Element::Keyword(_keyword) => (),
|
||||||
Drawer(_drawer) => (),
|
Element::Drawer(_drawer) => (),
|
||||||
Rule(_) => write!(w, "<hr>")?,
|
Element::Rule(_) => write!(w, "<hr>")?,
|
||||||
Cookie(cookie) => write!(w, "<code>{}</code>", cookie.value)?,
|
Element::Cookie(cookie) => write!(w, "<code>{}</code>", cookie.value)?,
|
||||||
Title(title) => write!(w, "<h{}>", if title.level <= 6 { title.level } else { 6 })?,
|
Element::Title(title) => {
|
||||||
Table(_) => (),
|
write!(w, "<h{}>", if title.level <= 6 { title.level } else { 6 })?
|
||||||
TableRow(_) => (),
|
}
|
||||||
TableCell => (),
|
Element::Table(_) => (),
|
||||||
|
Element::TableRow(_) => (),
|
||||||
|
Element::TableCell => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
fn end<W: Write>(&mut self, mut w: W, element: &Element) -> Result<(), E> {
|
|
||||||
use Element::*;
|
|
||||||
|
|
||||||
|
fn end<W: Write>(&mut self, mut w: W, element: &Element) -> Result<(), E> {
|
||||||
match element {
|
match element {
|
||||||
// container elements
|
// container elements
|
||||||
SpecialBlock(_) => (),
|
Element::SpecialBlock(_) => (),
|
||||||
QuoteBlock(_) => write!(w, "</blockquote>")?,
|
Element::QuoteBlock(_) => write!(w, "</blockquote>")?,
|
||||||
CenterBlock(_) => write!(w, "</div>")?,
|
Element::CenterBlock(_) => write!(w, "</div>")?,
|
||||||
VerseBlock(_) => write!(w, "</p>")?,
|
Element::VerseBlock(_) => write!(w, "</p>")?,
|
||||||
Bold => write!(w, "</b>")?,
|
Element::Bold => write!(w, "</b>")?,
|
||||||
Document { .. } => write!(w, "</main>")?,
|
Element::Document { .. } => write!(w, "</main>")?,
|
||||||
DynBlock(_dyn_block) => (),
|
Element::DynBlock(_dyn_block) => (),
|
||||||
Headline { .. } => (),
|
Element::Headline { .. } => (),
|
||||||
List(list) => {
|
Element::List(list) => {
|
||||||
if list.ordered {
|
if list.ordered {
|
||||||
write!(w, "</ol>")?;
|
write!(w, "</ol>")?;
|
||||||
} else {
|
} else {
|
||||||
write!(w, "</ul>")?;
|
write!(w, "</ul>")?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Italic => write!(w, "</i>")?,
|
Element::Italic => write!(w, "</i>")?,
|
||||||
ListItem(_) => write!(w, "</li>")?,
|
Element::ListItem(_) => write!(w, "</li>")?,
|
||||||
Paragraph { .. } => write!(w, "</p>")?,
|
Element::Paragraph { .. } => write!(w, "</p>")?,
|
||||||
Section => write!(w, "</section>")?,
|
Element::Section => write!(w, "</section>")?,
|
||||||
Strike => write!(w, "</s>")?,
|
Element::Strike => write!(w, "</s>")?,
|
||||||
Underline => write!(w, "</u>")?,
|
Element::Underline => write!(w, "</u>")?,
|
||||||
Title(title) => write!(w, "</h{}>", if title.level <= 6 { title.level } else { 6 })?,
|
Element::Title(title) => {
|
||||||
Table(_) => (),
|
write!(w, "</h{}>", if title.level <= 6 { title.level } else { 6 })?
|
||||||
TableRow(_) => (),
|
}
|
||||||
TableCell => (),
|
Element::Table(_) => (),
|
||||||
|
Element::TableRow(_) => (),
|
||||||
|
Element::TableCell => (),
|
||||||
// non-container elements
|
// non-container elements
|
||||||
_ => debug_assert!(!element.is_container()),
|
_ => debug_assert!(!element.is_container()),
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,103 +1,101 @@
|
||||||
use std::io::{Error, Write};
|
use std::io::{Error, Write};
|
||||||
|
|
||||||
use crate::elements::{Element, Timestamp};
|
use crate::elements::{Clock, Element, Table, Timestamp};
|
||||||
use crate::export::write_datetime;
|
use crate::export::write_datetime;
|
||||||
|
|
||||||
pub trait OrgHandler<E: From<Error>>: Default {
|
pub trait OrgHandler<E: From<Error>>: Default {
|
||||||
fn start<W: Write>(&mut self, mut w: W, element: &Element) -> Result<(), E> {
|
fn start<W: Write>(&mut self, mut w: W, element: &Element) -> Result<(), E> {
|
||||||
use Element::*;
|
|
||||||
|
|
||||||
match element {
|
match element {
|
||||||
// container elements
|
// container elements
|
||||||
SpecialBlock(block) => {
|
Element::SpecialBlock(block) => {
|
||||||
writeln!(w, "#+BEGIN_{}", block.name)?;
|
writeln!(w, "#+BEGIN_{}", block.name)?;
|
||||||
write_blank_lines(&mut w, block.pre_blank)?;
|
write_blank_lines(&mut w, block.pre_blank)?;
|
||||||
}
|
}
|
||||||
QuoteBlock(block) => {
|
Element::QuoteBlock(block) => {
|
||||||
writeln!(&mut w, "#+BEGIN_QUOTE")?;
|
writeln!(&mut w, "#+BEGIN_QUOTE")?;
|
||||||
write_blank_lines(&mut w, block.pre_blank)?;
|
write_blank_lines(&mut w, block.pre_blank)?;
|
||||||
}
|
}
|
||||||
CenterBlock(block) => {
|
Element::CenterBlock(block) => {
|
||||||
writeln!(&mut w, "#+BEGIN_CENTER")?;
|
writeln!(&mut w, "#+BEGIN_CENTER")?;
|
||||||
write_blank_lines(&mut w, block.pre_blank)?;
|
write_blank_lines(&mut w, block.pre_blank)?;
|
||||||
}
|
}
|
||||||
VerseBlock(block) => {
|
Element::VerseBlock(block) => {
|
||||||
writeln!(&mut w, "#+BEGIN_VERSE")?;
|
writeln!(&mut w, "#+BEGIN_VERSE")?;
|
||||||
write_blank_lines(&mut w, block.pre_blank)?;
|
write_blank_lines(&mut w, block.pre_blank)?;
|
||||||
}
|
}
|
||||||
Bold => write!(w, "*")?,
|
Element::Bold => write!(w, "*")?,
|
||||||
Document { pre_blank } => {
|
Element::Document { pre_blank } => {
|
||||||
write_blank_lines(w, *pre_blank)?;
|
write_blank_lines(w, *pre_blank)?;
|
||||||
}
|
}
|
||||||
DynBlock(dyn_block) => {
|
Element::DynBlock(dyn_block) => {
|
||||||
write!(&mut w, "#+BEGIN: {}", dyn_block.block_name)?;
|
write!(&mut w, "#+BEGIN: {}", dyn_block.block_name)?;
|
||||||
if let Some(parameters) = &dyn_block.arguments {
|
if let Some(parameters) = &dyn_block.arguments {
|
||||||
write!(&mut w, " {}", parameters)?;
|
write!(&mut w, " {}", parameters)?;
|
||||||
}
|
}
|
||||||
write_blank_lines(&mut w, dyn_block.pre_blank + 1)?;
|
write_blank_lines(&mut w, dyn_block.pre_blank + 1)?;
|
||||||
}
|
}
|
||||||
Headline { .. } => (),
|
Element::Headline { .. } => (),
|
||||||
List(_list) => (),
|
Element::List(_list) => (),
|
||||||
Italic => write!(w, "/")?,
|
Element::Italic => write!(w, "/")?,
|
||||||
ListItem(list_item) => {
|
Element::ListItem(list_item) => {
|
||||||
for _ in 0..list_item.indent {
|
for _ in 0..list_item.indent {
|
||||||
write!(&mut w, " ")?;
|
write!(&mut w, " ")?;
|
||||||
}
|
}
|
||||||
write!(&mut w, "{}", list_item.bullet)?;
|
write!(&mut w, "{}", list_item.bullet)?;
|
||||||
}
|
}
|
||||||
Paragraph { .. } => (),
|
Element::Paragraph { .. } => (),
|
||||||
Section => (),
|
Element::Section => (),
|
||||||
Strike => write!(w, "+")?,
|
Element::Strike => write!(w, "+")?,
|
||||||
Underline => write!(w, "_")?,
|
Element::Underline => write!(w, "_")?,
|
||||||
Drawer(drawer) => {
|
Element::Drawer(drawer) => {
|
||||||
writeln!(&mut w, ":{}:", drawer.name)?;
|
writeln!(&mut w, ":{}:", drawer.name)?;
|
||||||
write_blank_lines(&mut w, drawer.pre_blank)?;
|
write_blank_lines(&mut w, drawer.pre_blank)?;
|
||||||
}
|
}
|
||||||
// non-container elements
|
// non-container elements
|
||||||
CommentBlock(block) => {
|
Element::CommentBlock(block) => {
|
||||||
writeln!(&mut w, "#+BEGIN_COMMENT")?;
|
writeln!(&mut w, "#+BEGIN_COMMENT")?;
|
||||||
write!(&mut w, "{}", block.contents)?;
|
write!(&mut w, "{}", block.contents)?;
|
||||||
writeln!(&mut w, "#+END_COMMENT")?;
|
writeln!(&mut w, "#+END_COMMENT")?;
|
||||||
write_blank_lines(&mut w, block.post_blank)?;
|
write_blank_lines(&mut w, block.post_blank)?;
|
||||||
}
|
}
|
||||||
ExampleBlock(block) => {
|
Element::ExampleBlock(block) => {
|
||||||
writeln!(&mut w, "#+BEGIN_EXAMPLE")?;
|
writeln!(&mut w, "#+BEGIN_EXAMPLE")?;
|
||||||
write!(&mut w, "{}", block.contents)?;
|
write!(&mut w, "{}", block.contents)?;
|
||||||
writeln!(&mut w, "#+END_EXAMPLE")?;
|
writeln!(&mut w, "#+END_EXAMPLE")?;
|
||||||
write_blank_lines(&mut w, block.post_blank)?;
|
write_blank_lines(&mut w, block.post_blank)?;
|
||||||
}
|
}
|
||||||
ExportBlock(block) => {
|
Element::ExportBlock(block) => {
|
||||||
writeln!(&mut w, "#+BEGIN_EXPORT {}", block.data)?;
|
writeln!(&mut w, "#+BEGIN_EXPORT {}", block.data)?;
|
||||||
write!(&mut w, "{}", block.contents)?;
|
write!(&mut w, "{}", block.contents)?;
|
||||||
writeln!(&mut w, "#+END_EXPORT")?;
|
writeln!(&mut w, "#+END_EXPORT")?;
|
||||||
write_blank_lines(&mut w, block.post_blank)?;
|
write_blank_lines(&mut w, block.post_blank)?;
|
||||||
}
|
}
|
||||||
SourceBlock(block) => {
|
Element::SourceBlock(block) => {
|
||||||
writeln!(&mut w, "#+BEGIN_SRC {}", block.language)?;
|
writeln!(&mut w, "#+BEGIN_SRC {}", block.language)?;
|
||||||
write!(&mut w, "{}", block.contents)?;
|
write!(&mut w, "{}", block.contents)?;
|
||||||
writeln!(&mut w, "#+END_SRC")?;
|
writeln!(&mut w, "#+END_SRC")?;
|
||||||
write_blank_lines(&mut w, block.post_blank)?;
|
write_blank_lines(&mut w, block.post_blank)?;
|
||||||
}
|
}
|
||||||
BabelCall(call) => {
|
Element::BabelCall(call) => {
|
||||||
writeln!(&mut w, "#+CALL: {}", call.value)?;
|
writeln!(&mut w, "#+CALL: {}", call.value)?;
|
||||||
write_blank_lines(w, call.post_blank)?;
|
write_blank_lines(w, call.post_blank)?;
|
||||||
}
|
}
|
||||||
InlineSrc(inline_src) => {
|
Element::InlineSrc(inline_src) => {
|
||||||
write!(&mut w, "src_{}", inline_src.lang)?;
|
write!(&mut w, "src_{}", inline_src.lang)?;
|
||||||
if let Some(options) = &inline_src.options {
|
if let Some(options) = &inline_src.options {
|
||||||
write!(&mut w, "[{}]", options)?;
|
write!(&mut w, "[{}]", options)?;
|
||||||
}
|
}
|
||||||
write!(&mut w, "{{{}}}", inline_src.body)?;
|
write!(&mut w, "{{{}}}", inline_src.body)?;
|
||||||
}
|
}
|
||||||
Code { value } => write!(w, "~{}~", value)?,
|
Element::Code { value } => write!(w, "~{}~", value)?,
|
||||||
FnRef(fn_ref) => {
|
Element::FnRef(fn_ref) => {
|
||||||
write!(&mut w, "[fn:{}", fn_ref.label)?;
|
write!(&mut w, "[fn:{}", fn_ref.label)?;
|
||||||
if let Some(definition) = &fn_ref.definition {
|
if let Some(definition) = &fn_ref.definition {
|
||||||
write!(&mut w, ":{}", definition)?;
|
write!(&mut w, ":{}", definition)?;
|
||||||
}
|
}
|
||||||
write!(&mut w, "]")?;
|
write!(&mut w, "]")?;
|
||||||
}
|
}
|
||||||
InlineCall(inline_call) => {
|
Element::InlineCall(inline_call) => {
|
||||||
write!(&mut w, "call_{}", inline_call.name)?;
|
write!(&mut w, "call_{}", inline_call.name)?;
|
||||||
if let Some(header) = &inline_call.inside_header {
|
if let Some(header) = &inline_call.inside_header {
|
||||||
write!(&mut w, "[{}]", header)?;
|
write!(&mut w, "[{}]", header)?;
|
||||||
|
@ -107,28 +105,26 @@ pub trait OrgHandler<E: From<Error>>: Default {
|
||||||
write!(&mut w, "[{}]", header)?;
|
write!(&mut w, "[{}]", header)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Link(link) => {
|
Element::Link(link) => {
|
||||||
write!(&mut w, "[[{}]", link.path)?;
|
write!(&mut w, "[[{}]", link.path)?;
|
||||||
if let Some(desc) = &link.desc {
|
if let Some(desc) = &link.desc {
|
||||||
write!(&mut w, "[{}]", desc)?;
|
write!(&mut w, "[{}]", desc)?;
|
||||||
}
|
}
|
||||||
write!(&mut w, "]")?;
|
write!(&mut w, "]")?;
|
||||||
}
|
}
|
||||||
Macros(_macros) => (),
|
Element::Macros(_macros) => (),
|
||||||
RadioTarget => (),
|
Element::RadioTarget => (),
|
||||||
Snippet(snippet) => write!(w, "@@{}:{}@@", snippet.name, snippet.value)?,
|
Element::Snippet(snippet) => write!(w, "@@{}:{}@@", snippet.name, snippet.value)?,
|
||||||
Target(_target) => (),
|
Element::Target(_target) => (),
|
||||||
Text { value } => write!(w, "{}", value)?,
|
Element::Text { value } => write!(w, "{}", value)?,
|
||||||
Timestamp(timestamp) => {
|
Element::Timestamp(timestamp) => {
|
||||||
write_timestamp(&mut w, ×tamp)?;
|
write_timestamp(&mut w, ×tamp)?;
|
||||||
}
|
}
|
||||||
Verbatim { value } => write!(w, "={}=", value)?,
|
Element::Verbatim { value } => write!(w, "={}=", value)?,
|
||||||
FnDef(fn_def) => {
|
Element::FnDef(fn_def) => {
|
||||||
write_blank_lines(w, fn_def.post_blank)?;
|
write_blank_lines(w, fn_def.post_blank)?;
|
||||||
}
|
}
|
||||||
Clock(clock) => {
|
Element::Clock(clock) => {
|
||||||
use crate::elements::Clock;
|
|
||||||
|
|
||||||
write!(w, "CLOCK: ")?;
|
write!(w, "CLOCK: ")?;
|
||||||
|
|
||||||
match clock {
|
match clock {
|
||||||
|
@ -152,15 +148,15 @@ pub trait OrgHandler<E: From<Error>>: Default {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Comment(comment) => {
|
Element::Comment(comment) => {
|
||||||
write!(w, "{}", comment.value)?;
|
write!(w, "{}", comment.value)?;
|
||||||
write_blank_lines(&mut w, comment.post_blank)?;
|
write_blank_lines(&mut w, comment.post_blank)?;
|
||||||
}
|
}
|
||||||
FixedWidth(fixed_width) => {
|
Element::FixedWidth(fixed_width) => {
|
||||||
write!(&mut w, "{}", fixed_width.value)?;
|
write!(&mut w, "{}", fixed_width.value)?;
|
||||||
write_blank_lines(&mut w, fixed_width.post_blank)?;
|
write_blank_lines(&mut w, fixed_width.post_blank)?;
|
||||||
}
|
}
|
||||||
Keyword(keyword) => {
|
Element::Keyword(keyword) => {
|
||||||
write!(&mut w, "#+{}", keyword.key)?;
|
write!(&mut w, "#+{}", keyword.key)?;
|
||||||
if let Some(optional) = &keyword.optional {
|
if let Some(optional) = &keyword.optional {
|
||||||
write!(&mut w, "[{}]", optional)?;
|
write!(&mut w, "[{}]", optional)?;
|
||||||
|
@ -168,12 +164,12 @@ pub trait OrgHandler<E: From<Error>>: Default {
|
||||||
writeln!(&mut w, ": {}", keyword.value)?;
|
writeln!(&mut w, ": {}", keyword.value)?;
|
||||||
write_blank_lines(&mut w, keyword.post_blank)?;
|
write_blank_lines(&mut w, keyword.post_blank)?;
|
||||||
}
|
}
|
||||||
Rule(rule) => {
|
Element::Rule(rule) => {
|
||||||
writeln!(w, "-----")?;
|
writeln!(w, "-----")?;
|
||||||
write_blank_lines(&mut w, rule.post_blank)?;
|
write_blank_lines(&mut w, rule.post_blank)?;
|
||||||
}
|
}
|
||||||
Cookie(_cookie) => (),
|
Element::Cookie(_cookie) => (),
|
||||||
Title(title) => {
|
Element::Title(title) => {
|
||||||
for _ in 0..title.level {
|
for _ in 0..title.level {
|
||||||
write!(&mut w, "*")?;
|
write!(&mut w, "*")?;
|
||||||
}
|
}
|
||||||
|
@ -185,58 +181,56 @@ pub trait OrgHandler<E: From<Error>>: Default {
|
||||||
}
|
}
|
||||||
write!(&mut w, " ")?;
|
write!(&mut w, " ")?;
|
||||||
}
|
}
|
||||||
Table(_) => (),
|
Element::Table(_) => (),
|
||||||
TableRow(_) => (),
|
Element::TableRow(_) => (),
|
||||||
TableCell => (),
|
Element::TableCell => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn end<W: Write>(&mut self, mut w: W, element: &Element) -> Result<(), E> {
|
fn end<W: Write>(&mut self, mut w: W, element: &Element) -> Result<(), E> {
|
||||||
use Element::*;
|
|
||||||
|
|
||||||
match element {
|
match element {
|
||||||
// container elements
|
// container elements
|
||||||
SpecialBlock(block) => {
|
Element::SpecialBlock(block) => {
|
||||||
writeln!(&mut w, "#+END_{}", block.name)?;
|
writeln!(&mut w, "#+END_{}", block.name)?;
|
||||||
write_blank_lines(&mut w, block.post_blank)?;
|
write_blank_lines(&mut w, block.post_blank)?;
|
||||||
}
|
}
|
||||||
QuoteBlock(block) => {
|
Element::QuoteBlock(block) => {
|
||||||
writeln!(&mut w, "#+END_QUOTE")?;
|
writeln!(&mut w, "#+END_QUOTE")?;
|
||||||
write_blank_lines(&mut w, block.post_blank)?;
|
write_blank_lines(&mut w, block.post_blank)?;
|
||||||
}
|
}
|
||||||
CenterBlock(block) => {
|
Element::CenterBlock(block) => {
|
||||||
writeln!(&mut w, "#+END_CENTER")?;
|
writeln!(&mut w, "#+END_CENTER")?;
|
||||||
write_blank_lines(&mut w, block.post_blank)?;
|
write_blank_lines(&mut w, block.post_blank)?;
|
||||||
}
|
}
|
||||||
VerseBlock(block) => {
|
Element::VerseBlock(block) => {
|
||||||
writeln!(&mut w, "#+END_VERSE")?;
|
writeln!(&mut w, "#+END_VERSE")?;
|
||||||
write_blank_lines(&mut w, block.post_blank)?;
|
write_blank_lines(&mut w, block.post_blank)?;
|
||||||
}
|
}
|
||||||
Bold => write!(w, "*")?,
|
Element::Bold => write!(w, "*")?,
|
||||||
Document { .. } => (),
|
Element::Document { .. } => (),
|
||||||
DynBlock(dyn_block) => {
|
Element::DynBlock(dyn_block) => {
|
||||||
writeln!(w, "#+END:")?;
|
writeln!(w, "#+END:")?;
|
||||||
write_blank_lines(w, dyn_block.post_blank)?;
|
write_blank_lines(w, dyn_block.post_blank)?;
|
||||||
}
|
}
|
||||||
Headline { .. } => (),
|
Element::Headline { .. } => (),
|
||||||
List(list) => {
|
Element::List(list) => {
|
||||||
write_blank_lines(w, list.post_blank)?;
|
write_blank_lines(w, list.post_blank)?;
|
||||||
}
|
}
|
||||||
Italic => write!(w, "/")?,
|
Element::Italic => write!(w, "/")?,
|
||||||
ListItem(_) => (),
|
Element::ListItem(_) => (),
|
||||||
Paragraph { post_blank } => {
|
Element::Paragraph { post_blank } => {
|
||||||
write_blank_lines(w, post_blank + 1)?;
|
write_blank_lines(w, post_blank + 1)?;
|
||||||
}
|
}
|
||||||
Section => (),
|
Element::Section => (),
|
||||||
Strike => write!(w, "+")?,
|
Element::Strike => write!(w, "+")?,
|
||||||
Underline => write!(w, "_")?,
|
Element::Underline => write!(w, "_")?,
|
||||||
Drawer(drawer) => {
|
Element::Drawer(drawer) => {
|
||||||
writeln!(&mut w, ":END:")?;
|
writeln!(&mut w, ":END:")?;
|
||||||
write_blank_lines(&mut w, drawer.post_blank)?;
|
write_blank_lines(&mut w, drawer.post_blank)?;
|
||||||
}
|
}
|
||||||
Title(title) => {
|
Element::Title(title) => {
|
||||||
if !title.tags.is_empty() {
|
if !title.tags.is_empty() {
|
||||||
write!(&mut w, " :")?;
|
write!(&mut w, " :")?;
|
||||||
for tag in &title.tags {
|
for tag in &title.tags {
|
||||||
|
@ -274,9 +268,14 @@ pub trait OrgHandler<E: From<Error>>: Default {
|
||||||
}
|
}
|
||||||
write_blank_lines(&mut w, title.post_blank)?;
|
write_blank_lines(&mut w, title.post_blank)?;
|
||||||
}
|
}
|
||||||
Table(_) => (),
|
Element::Table(Table::Org { post_blank, .. }) => {
|
||||||
TableRow(_) => (),
|
write_blank_lines(w, *post_blank)?;
|
||||||
TableCell => (),
|
}
|
||||||
|
Element::Table(Table::TableEl { post_blank, .. }) => {
|
||||||
|
write_blank_lines(w, *post_blank)?;
|
||||||
|
}
|
||||||
|
Element::TableRow(_) => (),
|
||||||
|
Element::TableCell => (),
|
||||||
// non-container elements
|
// non-container elements
|
||||||
_ => debug_assert!(!element.is_container()),
|
_ => debug_assert!(!element.is_container()),
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue