Skip to content

Conversation

@DavisVaughan
Copy link
Collaborator

@DavisVaughan DavisVaughan commented Aug 29, 2025

Merges into feature/wasm branch

#include <assert.h>
#include <ctype.h>
#include <string.h>
#include <wchar.h>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one didn't seem used, and the shims didn't provide a shim for it, so I removed

Comment on lines -834 to +833
while (isdigit(lexer->lookahead)) {
while (iswdigit(lexer->lookahead)) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for (size_t i = 0; i < NUM_HTML_TAG_NAMES_RULE_1; i++) {
if (strcmp(name, HTML_TAG_NAMES_RULE_1[i]) == 0) {
// FIXME: I'm guessing on the size here
if (strncmp(name, HTML_TAG_NAMES_RULE_1[i], name_length) == 0) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Someone other than me should think about these strncmp calls

[dependencies]
quarto-markdown-pandoc = { workspace = true }
wasm-bindgen = "0.2.84"
wasm-bindgen = "0.2.89"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +166 to +176
// Note: Not provided by https://github.com/cacticouncil/lilypad, but we needed
// this one too. We could contribute this back upstream? Note that
// `towlower()`'s C function docs say it is only guaranteed to work in 1:1
// mapping cases, so that is what we reimplement here as well.
// https://en.cppreference.com/w/c/string/wide/towlower
#[no_mangle]
pub unsafe extern "C" fn towlower(c: c_int) -> c_int {
char::from_u32(c as u32).map_or(0, |c| {
c.to_lowercase().next().map(|c| c as i32).unwrap_or(0)
})
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nearly straight from https://github.com/cacticouncil/lilypad/blob/main/src/c_shim.rs but I did need this one, which is a blessed tree-sitter function and you use it in your scanner

Comment on lines +19 to +45
```
cd crates/wasm-qmd-parser
# To work around this error, because Apple Clang doesn't work with wasm32-unknown-unknown?
# I believe this is not required on a Linux machine.
# Requires `brew install llvm`.
# https://github.com/briansmith/ring/issues/1824
# error: unable to create target: 'No available targets are compatible with triple "wasm32-unknown-unknown"'
export PATH="/opt/homebrew/opt/llvm/bin:$PATH"
# To tell rustc to include our C shims located in `wasm-sysroot`, which we eventually compile into the project
# with `c_shim.rs`.
# https://github.com/tree-sitter/tree-sitter/discussions/1550#discussioncomment-8445285
#
# It also seems like we need to define HAVE_ENDIAN_H to tell tree-sitter we have `endian.h`
# as it doesn't seem to pick up on that automatically?
# https://github.com/tree-sitter/tree-sitter/blob/0be215e152d58351d2691484b4398ceff041f2fb/lib/src/portable/endian.h#L18
export CFLAGS_wasm32_unknown_unknown="-I$(pwd)/wasm-sysroot -Wbad-function-cast -Wcast-function-type -fno-builtin -DHAVE_ENDIAN_H"
# To just build the wasm-qmd-parser crate
# cargo build --target wasm32-unknown-unknown
# To build the wasm-pack bundle
# Note that you'll need `opt-level = "s"` in your `profile.dev` cargo profile
# otherwise you can get a "too many locals" error.
wasm-pack build --target web --dev
```
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some bonkers instructions on how to build it, you should probably turn this into something more official

@cscheid cscheid merged commit 254a16d into feature/wasm Aug 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants