Skip to content

Commit

Permalink
Remove markdown support from wit-parser
Browse files Browse the repository at this point in the history
This is quite old at this point and I'm not aware of anyone using it or
planning to use it, so remove its support here to cut down on the deps
and size of `wit-parser`.
  • Loading branch information
alexcrichton committed Oct 6, 2023
1 parent 30cc3ae commit eb5a178
Show file tree
Hide file tree
Showing 7 changed files with 1 addition and 130 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion crates/wit-parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ Tooling for parsing `*.wit` files and working with their contents.
id-arena = "2"
anyhow = { workspace = true }
indexmap = { workspace = true, features = ["serde"] }
pulldown-cmark = { version = "0.9.3", default-features = false }
unicode-xid = "0.2.2"
log = { workspace = true }
url = { workspace = true }
Expand Down
43 changes: 1 addition & 42 deletions crates/wit-parser/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1199,55 +1199,14 @@ impl SourceMap {
/// interfaces and worlds defined together. Note that each file has its own
/// personal namespace, however, for top-level `use` and such.
pub fn push(&mut self, path: &Path, contents: impl Into<String>) {
let mut contents = contents.into();
if path.extension().and_then(|s| s.to_str()) == Some("md") {
log::debug!("automatically unwrapping markdown container");
contents = unwrap_md(&contents);
}
let contents = contents.into();
let new_offset = self.offset + u32::try_from(contents.len()).unwrap();
self.sources.push(Source {
offset: self.offset,
path: path.to_path_buf(),
contents,
});
self.offset = new_offset;

fn unwrap_md(contents: &str) -> String {
use pulldown_cmark::{CodeBlockKind, CowStr, Event, Options, Parser, Tag};

let mut wit = String::new();
let mut last_pos = 0;
let mut in_wit_code_block = false;
Parser::new_ext(contents, Options::empty())
.into_offset_iter()
.for_each(|(event, range)| match (event, range) {
(
Event::Start(Tag::CodeBlock(CodeBlockKind::Fenced(CowStr::Borrowed(
"wit",
)))),
_,
) => {
in_wit_code_block = true;
}
(Event::Text(text), range) if in_wit_code_block => {
// Ensure that offsets are correct by inserting newlines to
// cover the Markdown content outside of wit code blocks.
for _ in contents[last_pos..range.start].lines() {
wit.push('\n');
}
wit.push_str(&text);
last_pos = range.end;
}
(
Event::End(Tag::CodeBlock(CodeBlockKind::Fenced(CowStr::Borrowed("wit")))),
_,
) => {
in_wit_code_block = false;
}
_ => {}
});
wit
}
}

/// Parses the files added to this source map into an [`UnresolvedPackage`].
Expand Down
34 changes: 0 additions & 34 deletions crates/wit-parser/tests/ui/embedded.wit.md

This file was deleted.

40 changes: 0 additions & 40 deletions crates/wit-parser/tests/ui/embedded.wit.md.json

This file was deleted.

7 changes: 0 additions & 7 deletions crates/wit-parser/tests/ui/parse-fail/invalid-md.md

This file was deleted.

5 changes: 0 additions & 5 deletions crates/wit-parser/tests/ui/parse-fail/invalid-md.wit.result

This file was deleted.

0 comments on commit eb5a178

Please sign in to comment.