From b251441782e2546e5bda1e7bb8a9633109ad9dfb Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Mon, 5 Oct 2020 13:28:27 -0600 Subject: [PATCH] add example run on README --- README.gmi | 37 +++++++++++++++++++++++++++++++++++++ src/lib.rs | 10 +++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 README.gmi diff --git a/README.gmi b/README.gmi new file mode 100644 index 0000000..dee3cff --- /dev/null +++ b/README.gmi @@ -0,0 +1,37 @@ +# md2gemtext + +[image: builds.sr.ht status] +=> https://builds.sr.ht/~boringcactus/md2gemtext.svg [image: builds.sr.ht status] +=> https://builds.sr.ht/~boringcactus/md2gemtext? builds.sr.ht status + +for converting Markdown into gemtext. +=> https://gemini.circumlunar.space/docs/specification.html gemtext + +## standalone usage + +``` +cargo install md2gemtext +md2gemtext /path/to/some/file.md /path/to/some/file.gmi +``` + +## library usage + +``` +let gemtext = md2gemtext::convert("some markdown")?; +``` + +## translation rules + +* "thematic breaks" (hr tags) are translated to `-----` on a line by itself +* headings turn into headings, levels beyond 3 get capped at 3 +* code blocks get turned into code blocks (info strings are discarded) +* something happens to HTML, i forget what +* paragraphs get empty lines between them, because i think that looks better +* block quotes get turned into quotes (multi-paragraph contiguous block quotes break though) +* lists get turned into lists ("loose lists" probably misbehave, nested lists _definitely_ misbehave, numbering is not preserved) +* ``markdown code spans`` retain their backticks +* `_italics_` are surrounded by single underscores +* `**bold**` is surrounded by double asterisks +* `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]` +* if a link or image is its own paragraph, it becomes just the gemtext link, to not be redundant diff --git a/src/lib.rs b/src/lib.rs index 9469141..f5b2aee 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -211,7 +211,7 @@ impl State { #[cfg(test)] #[test] -fn run_tests() { +fn test_kitchen_sink() { let markdown_demo = r#" # h1 ## h2 @@ -276,3 +276,11 @@ fn test_list_start() { let gemtext = "> hi\n\n* uh\n* ah\n"; assert_eq!(convert(markdown), gemtext); } + +#[cfg(test)] +#[test] +fn test_readme() { + let markdown = include_str!("../README.md"); + let gemtext = include_str!("../README.gmi"); + assert_eq!(convert(markdown), gemtext); +}