Add simple preprocessor to handle descriptions interpreted by cargo doc

This seemed easiest, especially since I also am the author of
pulldown-cmark-to-cmark :D.

Funny how things fit together sometimes. And so much better than
if I would have tried the same in pure python.
This commit is contained in:
Sebastian Thiel
2019-07-05 14:50:05 +08:00
parent 85f080ce5e
commit 8cb73d66c2
3 changed files with 49 additions and 0 deletions

1
.gitignore vendored
View File

@@ -1,5 +1,6 @@
.DS_Store
/.vscode/
/.idea/
.timestamp
gen/doc
*.go

View File

@@ -0,0 +1,12 @@
[package]
name = "preproc"
version = "0.1.0"
authors = ["Sebastian Thiel <sthiel@thoughtworks.com>"]
edition = "2018"
publish = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
pulldown-cmark-to-cmark = "1.2.2"
pulldown-cmark = "0.5.2"

View File

@@ -0,0 +1,36 @@
extern crate pulldown_cmark;
extern crate pulldown_cmark_to_cmark;
use pulldown_cmark::Parser;
use pulldown_cmark_to_cmark::fmt::cmark;
use std::io::{self, Read, Write};
fn main() {
let md = {
let mut buf = String::with_capacity(2048);
io::stdin().read_to_string(&mut buf).unwrap();
buf
};
let mut output = String::with_capacity(2048);
cmark(
Parser::new_ext(&md, pulldown_cmark::Options::all()).map(|e| {
use pulldown_cmark::Event::*;
match e {
Start(ref tag) => {
use pulldown_cmark::Tag::*;
match tag {
CodeBlock(code) => Start(CodeBlock(format!("ignore{}", code).into())),
_ => e,
}
}
_ => e,
}
}),
&mut output,
None,
)
.unwrap();
io::stdout().write_all(&output.as_bytes()).unwrap();
}