tidy up README
parent
33fb649a36
commit
7a365baaaa
|
@ -26,10 +26,9 @@ let gemtext = md2gemtext::convert("some markdown")?;
|
||||||
- paragraphs get empty lines between them, because i think that looks better
|
- paragraphs get empty lines between them, because i think that looks better
|
||||||
- block quotes get turned into quotes
|
- block quotes get turned into quotes
|
||||||
- lists get turned into lists ("loose lists" probably misbehave, nested lists *definitely* misbehave, numbering is not preserved)
|
- lists get turned into lists ("loose lists" probably misbehave, nested lists *definitely* misbehave, numbering is not preserved)
|
||||||
- `code spans` turn into `\`code spans\``
|
- `` `markdown code spans` `` turn into `` `code spans` ``
|
||||||
- *italics* turn into `_italics_`
|
- `*markdown italics*` turn into `_italics_`
|
||||||
- **bold** turns into `**bold**`
|
- `**markdown bold**` turns into `**bold**`
|
||||||
- ~~strikethrough~~ turns into `~~strikethrough~~`
|
|
||||||
- `a [link](a://url) with context` turns into `a link with context` followed by `=> a://url link`
|
- `a [link](a://url) with context` turns into `a link with context` followed by `=> a://url link`
|
||||||
- `an ![inline](a://url) image` turns into `an [image: inline] image` followed by `=> a://url [image: inline]`
|
- `an ![inline](a://url) image` turns into `an [image: inline] image` followed by `=> a://url [image: inline]`
|
||||||
- if a link or image is its own paragraph, it becomes just the gemtext link, to not be redundant
|
- if a link or image is its own paragraph, it becomes just the gemtext link, to not be redundant
|
||||||
|
|
12
src/lib.rs
12
src/lib.rs
|
@ -7,9 +7,7 @@ use pulldown_cmark as md;
|
||||||
/// Will panic if gemtext::render somehow produces invalid UTF-8.
|
/// Will panic if gemtext::render somehow produces invalid UTF-8.
|
||||||
/// Since gemtext::render only produces valid UTF-8, this should never happen.
|
/// Since gemtext::render only produces valid UTF-8, this should never happen.
|
||||||
pub fn convert(markdown_text: &str) -> String {
|
pub fn convert(markdown_text: &str) -> String {
|
||||||
let mut options = md::Options::empty();
|
let parser = md::Parser::new_ext(markdown_text, md::Options::empty());
|
||||||
options.insert(md::Options::ENABLE_STRIKETHROUGH);
|
|
||||||
let parser = md::Parser::new_ext(markdown_text, options);
|
|
||||||
let mut state = State::new();
|
let mut state = State::new();
|
||||||
|
|
||||||
for event in parser {
|
for event in parser {
|
||||||
|
@ -28,7 +26,7 @@ pub fn convert(markdown_text: &str) -> String {
|
||||||
md::Event::Start(md::Tag::TableCell) => unimplemented!("tables disabled"),
|
md::Event::Start(md::Tag::TableCell) => unimplemented!("tables disabled"),
|
||||||
md::Event::Start(md::Tag::Emphasis) => state.toggle_emphasis(),
|
md::Event::Start(md::Tag::Emphasis) => state.toggle_emphasis(),
|
||||||
md::Event::Start(md::Tag::Strong) => state.toggle_strong(),
|
md::Event::Start(md::Tag::Strong) => state.toggle_strong(),
|
||||||
md::Event::Start(md::Tag::Strikethrough) => state.toggle_strikethrough(),
|
md::Event::Start(md::Tag::Strikethrough) => unimplemented!("strikethrough disabled"),
|
||||||
md::Event::Start(md::Tag::Link(_, _, _)) => state.start_link(),
|
md::Event::Start(md::Tag::Link(_, _, _)) => state.start_link(),
|
||||||
md::Event::Start(md::Tag::Image(_, _, _)) => state.start_image(),
|
md::Event::Start(md::Tag::Image(_, _, _)) => state.start_image(),
|
||||||
|
|
||||||
|
@ -45,7 +43,7 @@ pub fn convert(markdown_text: &str) -> String {
|
||||||
md::Event::End(md::Tag::TableCell) => unimplemented!("tables disabled"),
|
md::Event::End(md::Tag::TableCell) => unimplemented!("tables disabled"),
|
||||||
md::Event::End(md::Tag::Emphasis) => state.toggle_emphasis(),
|
md::Event::End(md::Tag::Emphasis) => state.toggle_emphasis(),
|
||||||
md::Event::End(md::Tag::Strong) => state.toggle_strong(),
|
md::Event::End(md::Tag::Strong) => state.toggle_strong(),
|
||||||
md::Event::End(md::Tag::Strikethrough) => state.toggle_strikethrough(),
|
md::Event::End(md::Tag::Strikethrough) => unimplemented!("strikethrough disabled"),
|
||||||
md::Event::End(md::Tag::Link(_, href, _)) => state.end_link(&href),
|
md::Event::End(md::Tag::Link(_, href, _)) => state.end_link(&href),
|
||||||
md::Event::End(md::Tag::Image(_, src, _)) => state.end_image(&src),
|
md::Event::End(md::Tag::Image(_, src, _)) => state.end_image(&src),
|
||||||
|
|
||||||
|
@ -152,10 +150,6 @@ impl State {
|
||||||
self.add_text("**");
|
self.add_text("**");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn toggle_strikethrough(&mut self) {
|
|
||||||
self.add_text("~~");
|
|
||||||
}
|
|
||||||
|
|
||||||
fn start_link(&mut self) {
|
fn start_link(&mut self) {
|
||||||
self.link_text_stack.push(String::new());
|
self.link_text_stack.push(String::new());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue