mirror of https://github.com/yewstack/yew
Bump the cargo-deps group across 1 directory with 23 updates (#3713)
* Bump the cargo-deps group across 1 directory with 23 updates Bumps the cargo-deps group with 20 updates in the / directory: | Package | From | To | | --- | --- | --- | | [indexmap](https://github.com/indexmap-rs/indexmap) | `2.3.0` | `2.4.0` | | [js-sys](https://github.com/rustwasm/wasm-bindgen) | `0.3.69` | `0.3.70` | | [thiserror](https://github.com/dtolnay/thiserror) | `1.0.55` | `1.0.63` | | [serde](https://github.com/serde-rs/serde) | `1.0.193` | `1.0.208` | | [web-sys](https://github.com/rustwasm/wasm-bindgen) | `0.3.69` | `0.3.70` | | [wasm-bindgen-futures](https://github.com/rustwasm/wasm-bindgen) | `0.4.42` | `0.4.43` | | [wasm-bindgen-test](https://github.com/rustwasm/wasm-bindgen) | `0.3.42` | `0.3.43` | | [trybuild](https://github.com/dtolnay/trybuild) | `1.0.86` | `1.0.99` | | [syn](https://github.com/dtolnay/syn) | `2.0.72` | `2.0.75` | | [getrandom](https://github.com/rust-random/getrandom) | `0.2.14` | `0.2.15` | | [tabled](https://github.com/zhiburt/tabled) | `0.15.0` | `0.16.0` | | [clap](https://github.com/clap-rs/clap) | `4.5.13` | `4.5.16` | | [reqwest](https://github.com/seanmonstar/reqwest) | `0.12.5` | `0.12.7` | | [derive_more](https://github.com/JelteF/derive_more) | `0.99.18` | `1.0.0` | | [gloo-net](https://github.com/rustwasm/gloo) | `0.5.0` | `0.6.0` | | [pulldown-cmark](https://github.com/raphlinus/pulldown-cmark) | `0.9.6` | `0.12.0` | | [hyper-util](https://github.com/hyperium/hyper-util) | `0.1.6` | `0.1.7` | | [tower](https://github.com/tower-rs/tower) | `0.4.13` | `0.5.0` | | [env_logger](https://github.com/rust-cli/env_logger) | `0.10.2` | `0.11.5` | | [postcard](https://github.com/jamesmunns/postcard) | `1.0.8` | `1.0.10` | Updates `indexmap` from 2.3.0 to 2.4.0 - [Changelog](https://github.com/indexmap-rs/indexmap/blob/master/RELEASES.md) - [Commits](https://github.com/indexmap-rs/indexmap/compare/2.3.0...2.4.0) Updates `js-sys` from 0.3.69 to 0.3.70 - [Release notes](https://github.com/rustwasm/wasm-bindgen/releases) - [Changelog](https://github.com/rustwasm/wasm-bindgen/blob/main/CHANGELOG.md) - [Commits](https://github.com/rustwasm/wasm-bindgen/commits) Updates `wasm-bindgen` from 0.2.92 to 0.2.93 - [Release notes](https://github.com/rustwasm/wasm-bindgen/releases) - [Changelog](https://github.com/rustwasm/wasm-bindgen/blob/main/CHANGELOG.md) - [Commits](https://github.com/rustwasm/wasm-bindgen/compare/0.2.92...0.2.93) Updates `thiserror` from 1.0.55 to 1.0.63 - [Release notes](https://github.com/dtolnay/thiserror/releases) - [Commits](https://github.com/dtolnay/thiserror/compare/1.0.55...1.0.63) Updates `serde` from 1.0.193 to 1.0.208 - [Release notes](https://github.com/serde-rs/serde/releases) - [Commits](https://github.com/serde-rs/serde/compare/v1.0.193...v1.0.208) Updates `web-sys` from 0.3.69 to 0.3.70 - [Release notes](https://github.com/rustwasm/wasm-bindgen/releases) - [Changelog](https://github.com/rustwasm/wasm-bindgen/blob/main/CHANGELOG.md) - [Commits](https://github.com/rustwasm/wasm-bindgen/commits) Updates `wasm-bindgen-futures` from 0.4.42 to 0.4.43 - [Release notes](https://github.com/rustwasm/wasm-bindgen/releases) - [Changelog](https://github.com/rustwasm/wasm-bindgen/blob/main/CHANGELOG.md) - [Commits](https://github.com/rustwasm/wasm-bindgen/commits) Updates `wasm-bindgen-test` from 0.3.42 to 0.3.43 - [Release notes](https://github.com/rustwasm/wasm-bindgen/releases) - [Changelog](https://github.com/rustwasm/wasm-bindgen/blob/main/CHANGELOG.md) - [Commits](https://github.com/rustwasm/wasm-bindgen/commits) Updates `trybuild` from 1.0.86 to 1.0.99 - [Release notes](https://github.com/dtolnay/trybuild/releases) - [Commits](https://github.com/dtolnay/trybuild/compare/1.0.86...1.0.99) Updates `syn` from 2.0.72 to 2.0.75 - [Release notes](https://github.com/dtolnay/syn/releases) - [Commits](https://github.com/dtolnay/syn/compare/2.0.72...2.0.75) Updates `getrandom` from 0.2.14 to 0.2.15 - [Changelog](https://github.com/rust-random/getrandom/blob/master/CHANGELOG.md) - [Commits](https://github.com/rust-random/getrandom/compare/v0.2.14...v0.2.15) Updates `tabled` from 0.15.0 to 0.16.0 - [Changelog](https://github.com/zhiburt/tabled/blob/master/CHANGELOG.md) - [Commits](https://github.com/zhiburt/tabled/commits) Updates `serde_json` from 1.0.109 to 1.0.125 - [Release notes](https://github.com/serde-rs/json/releases) - [Commits](https://github.com/serde-rs/json/compare/v1.0.109...1.0.125) Updates `clap` from 4.5.13 to 4.5.16 - [Release notes](https://github.com/clap-rs/clap/releases) - [Changelog](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md) - [Commits](https://github.com/clap-rs/clap/compare/clap_complete-v4.5.13...clap_complete-v4.5.16) Updates `reqwest` from 0.12.5 to 0.12.7 - [Release notes](https://github.com/seanmonstar/reqwest/releases) - [Changelog](https://github.com/seanmonstar/reqwest/blob/master/CHANGELOG.md) - [Commits](https://github.com/seanmonstar/reqwest/compare/v0.12.5...v0.12.7) Updates `derive_more` from 0.99.18 to 1.0.0 - [Release notes](https://github.com/JelteF/derive_more/releases) - [Changelog](https://github.com/JelteF/derive_more/blob/master/CHANGELOG.md) - [Commits](https://github.com/JelteF/derive_more/compare/v0.99.18...v1.0.0) Updates `gloo-net` from 0.5.0 to 0.6.0 - [Release notes](https://github.com/rustwasm/gloo/releases) - [Changelog](https://github.com/rustwasm/gloo/blob/master/CHANGELOG.md) - [Commits](https://github.com/rustwasm/gloo/compare/0.5.0...0.6.0) Updates `pulldown-cmark` from 0.9.6 to 0.12.0 - [Release notes](https://github.com/raphlinus/pulldown-cmark/releases) - [Commits](https://github.com/raphlinus/pulldown-cmark/compare/v0.9.6...v0.12.0) Updates `hyper-util` from 0.1.6 to 0.1.7 - [Release notes](https://github.com/hyperium/hyper-util/releases) - [Changelog](https://github.com/hyperium/hyper-util/blob/master/CHANGELOG.md) - [Commits](https://github.com/hyperium/hyper-util/compare/v0.1.6...v0.1.7) Updates `tower` from 0.4.13 to 0.5.0 - [Release notes](https://github.com/tower-rs/tower/releases) - [Commits](https://github.com/tower-rs/tower/compare/tower-0.4.13...tower-0.5.0) Updates `env_logger` from 0.10.2 to 0.11.5 - [Release notes](https://github.com/rust-cli/env_logger/releases) - [Changelog](https://github.com/rust-cli/env_logger/blob/main/CHANGELOG.md) - [Commits](https://github.com/rust-cli/env_logger/compare/v0.10.2...v0.11.5) Updates `serde_derive` from 1.0.193 to 1.0.208 - [Release notes](https://github.com/serde-rs/serde/releases) - [Commits](https://github.com/serde-rs/serde/compare/v1.0.193...v1.0.208) Updates `postcard` from 1.0.8 to 1.0.10 - [Release notes](https://github.com/jamesmunns/postcard/releases) - [Changelog](https://github.com/jamesmunns/postcard/blob/main/CHANGELOG.md) - [Commits](https://github.com/jamesmunns/postcard/compare/v1.0.8...v1.0.10) --- updated-dependencies: - dependency-name: indexmap dependency-type: direct:production update-type: version-update:semver-minor dependency-group: cargo-deps - dependency-name: js-sys dependency-type: direct:production update-type: version-update:semver-patch dependency-group: cargo-deps - dependency-name: wasm-bindgen dependency-type: direct:production update-type: version-update:semver-patch dependency-group: cargo-deps - dependency-name: thiserror dependency-type: direct:production update-type: version-update:semver-patch dependency-group: cargo-deps - dependency-name: serde dependency-type: direct:production update-type: version-update:semver-patch dependency-group: cargo-deps - dependency-name: web-sys dependency-type: direct:production update-type: version-update:semver-patch dependency-group: cargo-deps - dependency-name: wasm-bindgen-futures dependency-type: direct:production update-type: version-update:semver-patch dependency-group: cargo-deps - dependency-name: wasm-bindgen-test dependency-type: direct:production update-type: version-update:semver-patch dependency-group: cargo-deps - dependency-name: trybuild dependency-type: direct:production update-type: version-update:semver-patch dependency-group: cargo-deps - dependency-name: syn dependency-type: direct:production update-type: version-update:semver-patch dependency-group: cargo-deps - dependency-name: getrandom dependency-type: direct:production update-type: version-update:semver-patch dependency-group: cargo-deps - dependency-name: tabled dependency-type: direct:production update-type: version-update:semver-minor dependency-group: cargo-deps - dependency-name: serde_json dependency-type: direct:production update-type: version-update:semver-patch dependency-group: cargo-deps - dependency-name: clap dependency-type: direct:production update-type: version-update:semver-patch dependency-group: cargo-deps - dependency-name: reqwest dependency-type: direct:production update-type: version-update:semver-patch dependency-group: cargo-deps - dependency-name: derive_more dependency-type: direct:production update-type: version-update:semver-major dependency-group: cargo-deps - dependency-name: gloo-net dependency-type: direct:production update-type: version-update:semver-minor dependency-group: cargo-deps - dependency-name: pulldown-cmark dependency-type: direct:production update-type: version-update:semver-minor dependency-group: cargo-deps - dependency-name: hyper-util dependency-type: direct:production update-type: version-update:semver-patch dependency-group: cargo-deps - dependency-name: tower dependency-type: direct:production update-type: version-update:semver-minor dependency-group: cargo-deps - dependency-name: env_logger dependency-type: direct:production update-type: version-update:semver-minor dependency-group: cargo-deps - dependency-name: serde_derive dependency-type: direct:production update-type: version-update:semver-patch dependency-group: cargo-deps - dependency-name: postcard dependency-type: direct:production update-type: version-update:semver-patch dependency-group: cargo-deps ... Signed-off-by: dependabot[bot] <support@github.com> * fix markup parsing * update web_sys bindings to non-deprecated * fix formatting * fix feature set for derive_more * update lock file to work around tower-rs/tower#784 --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Martin Molzer <WorldSEnder@users.noreply.github.com>
This commit is contained in:
parent
3871418174
commit
aa211192a9
|
@ -45,3 +45,6 @@ jobs:
|
|||
# Only push when this is a non-pr commit that has been benchmarked, i.e. master
|
||||
auto-push: ${{ fromJSON(steps.test-pr.outputs.stdout).number == '' }}
|
||||
save-data-file: ${{ fromJSON(steps.test-pr.outputs.stdout).number == '' }}
|
||||
# Enable job summary
|
||||
summary-always: true
|
||||
comment-always: true
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -27,7 +27,7 @@ for path in examples/*; do
|
|||
dist_dir="$output/$example"
|
||||
export RUSTFLAGS="--cfg nightly_yew"
|
||||
|
||||
trunk build --release --dist "$dist_dir" --public-url "$PUBLIC_URL_PREFIX/$example"
|
||||
trunk build --release --dist "$dist_dir" --public-url "$PUBLIC_URL_PREFIX/$example" --no-sri
|
||||
|
||||
# check that there are no undefined symbols. Those generate an import .. from 'env',
|
||||
# which isn't available in the browser.
|
||||
|
|
|
@ -9,4 +9,4 @@ license = "MIT OR Apache-2.0"
|
|||
yew = { path = "../../packages/yew", features = ["csr"] }
|
||||
chrono = "0.4"
|
||||
futures = "0.3"
|
||||
gloo-net = "0.5"
|
||||
gloo-net = "0.6"
|
||||
|
|
|
@ -13,7 +13,7 @@ gloo = "0.11"
|
|||
wasm-bindgen = "0.2"
|
||||
|
||||
[dependencies.web-sys]
|
||||
version = "0.3.69"
|
||||
version = "0.3.70"
|
||||
features = [
|
||||
"Document",
|
||||
"Element",
|
||||
|
|
|
@ -6,7 +6,7 @@ edition = "2021"
|
|||
license = "MIT OR Apache-2.0"
|
||||
|
||||
[dependencies]
|
||||
pulldown-cmark = { version = "0.9", default-features = false }
|
||||
pulldown-cmark = { version = "0.12", default-features = false }
|
||||
wasm-bindgen = "0.2"
|
||||
wasm-bindgen-futures = "0.4"
|
||||
yew = { path = "../../packages/yew", features = ["csr"] }
|
||||
|
|
|
@ -43,9 +43,9 @@ pub enum FetchState<T> {
|
|||
/// Consult the following for an example of the fetch api by the team behind web_sys:
|
||||
/// https://rustwasm.github.io/wasm-bindgen/examples/fetch.html
|
||||
async fn fetch_markdown(url: &'static str) -> Result<String, FetchError> {
|
||||
let mut opts = RequestInit::new();
|
||||
opts.method("GET");
|
||||
opts.mode(RequestMode::Cors);
|
||||
let opts = RequestInit::new();
|
||||
opts.set_method("GET");
|
||||
opts.set_mode(RequestMode::Cors);
|
||||
|
||||
let request = Request::new_with_str_and_init(url, &opts)?;
|
||||
|
||||
|
|
|
@ -1,199 +1,258 @@
|
|||
/// Original author of this code is [Nathan Ringo](https://github.com/remexre)
|
||||
/// Source: https://github.com/acmumn/mentoring/blob/master/web-client/src/view/markdown.rs
|
||||
use std::rc::Rc;
|
||||
|
||||
use pulldown_cmark::{Alignment, CodeBlockKind, Event, Options, Parser, Tag};
|
||||
use pulldown_cmark::{Alignment, CodeBlockKind, Event, Options, Parser, Tag, TagEnd};
|
||||
use yew::virtual_dom::{VNode, VTag, VText};
|
||||
use yew::{html, Classes, Html};
|
||||
use yew::Html;
|
||||
|
||||
/// Adds a class to the VTag.
|
||||
/// You can also provide multiple classes separated by ascii whitespaces.
|
||||
///
|
||||
/// Note that this has a complexity of O(n),
|
||||
/// where n is the number of classes already in VTag plus
|
||||
/// the number of classes to be added.
|
||||
fn add_class(vtag: &mut VTag, class: impl Into<Classes>) {
|
||||
let mut classes: Classes = vtag
|
||||
.attributes
|
||||
.iter()
|
||||
.find(|(k, _)| *k == "class")
|
||||
.map(|(_, v)| Classes::from(v.to_owned()))
|
||||
.unwrap_or_default();
|
||||
classes.push(class);
|
||||
vtag.add_attribute("class", classes.to_string());
|
||||
struct TableContext {
|
||||
next_cell_index: usize,
|
||||
in_head: bool,
|
||||
has_body: bool,
|
||||
alignment: Vec<Alignment>,
|
||||
}
|
||||
|
||||
struct TagWriter {
|
||||
root_children: Vec<VNode>,
|
||||
spine: Vec<VTag>,
|
||||
table_ctx: Option<TableContext>,
|
||||
}
|
||||
|
||||
impl TagWriter {
|
||||
fn new() -> Self {
|
||||
Self {
|
||||
root_children: vec![],
|
||||
spine: vec![],
|
||||
table_ctx: None,
|
||||
}
|
||||
}
|
||||
|
||||
fn finish(mut self) -> VNode {
|
||||
assert!(
|
||||
self.spine.is_empty(),
|
||||
"expected all nested elements to be closed"
|
||||
);
|
||||
if self.root_children.len() == 1 {
|
||||
self.root_children.pop().unwrap()
|
||||
} else {
|
||||
self.root_children.into_iter().collect()
|
||||
}
|
||||
}
|
||||
|
||||
fn add_child(&mut self, child: VNode) {
|
||||
if let Some(host) = self.spine.last_mut() {
|
||||
host.add_child(child);
|
||||
} else {
|
||||
self.root_children.push(child);
|
||||
}
|
||||
}
|
||||
|
||||
fn pop_spine(&mut self) {
|
||||
let top = self.spine.pop().expect("an element to close");
|
||||
self.add_child(top.into());
|
||||
}
|
||||
|
||||
fn get_table_ctx(&mut self) -> &mut TableContext {
|
||||
self.table_ctx.as_mut().expect("a table context")
|
||||
}
|
||||
|
||||
fn open_table_ctx(&mut self, alignment: Vec<Alignment>) {
|
||||
assert!(self.table_ctx.is_none(), "nested tables not supported");
|
||||
self.table_ctx = Some(TableContext {
|
||||
next_cell_index: 0,
|
||||
in_head: false,
|
||||
has_body: false,
|
||||
alignment,
|
||||
});
|
||||
}
|
||||
|
||||
fn close_table_ctx(&mut self) -> TableContext {
|
||||
self.table_ctx.take().expect("expected to be in a table")
|
||||
}
|
||||
|
||||
fn start_tag(&mut self, tag: Tag) {
|
||||
let wrapper = match tag {
|
||||
Tag::Paragraph => VTag::new("p"),
|
||||
Tag::Heading { level, .. } => VTag::new(level.to_string()),
|
||||
Tag::BlockQuote(_) => {
|
||||
let mut el = VTag::new("blockquote");
|
||||
el.add_attribute("class", "blockquote");
|
||||
el
|
||||
}
|
||||
Tag::CodeBlock(code_block_kind) => {
|
||||
self.spine.push(VTag::new("pre"));
|
||||
|
||||
let mut el = VTag::new("code");
|
||||
if let CodeBlockKind::Fenced(lang) = code_block_kind {
|
||||
// Different color schemes may be used for different code blocks,
|
||||
// but a different library (likely js based at the moment) would be necessary to
|
||||
// actually provide the highlighting support by locating the
|
||||
// language classes and applying dom transforms on their contents.
|
||||
match lang.as_ref() {
|
||||
"html" => el.add_attribute("class", "html-language"),
|
||||
"rust" => el.add_attribute("class", "rust-language"),
|
||||
"java" => el.add_attribute("class", "java-language"),
|
||||
"c" => el.add_attribute("class", "c-language"),
|
||||
_ => {} // Add your own language highlighting support
|
||||
};
|
||||
}
|
||||
|
||||
el
|
||||
}
|
||||
Tag::List(None) => VTag::new("ul"),
|
||||
Tag::List(Some(1)) => VTag::new("ol"),
|
||||
Tag::List(Some(ref start)) => {
|
||||
let mut el = VTag::new("ol");
|
||||
el.add_attribute("start", start.to_string());
|
||||
el
|
||||
}
|
||||
Tag::Item => VTag::new("li"),
|
||||
Tag::Table(alignment) => {
|
||||
self.open_table_ctx(alignment);
|
||||
let mut el = VTag::new("table");
|
||||
el.add_attribute("class", "table");
|
||||
el
|
||||
}
|
||||
Tag::TableHead => {
|
||||
let ctx = self.get_table_ctx();
|
||||
ctx.next_cell_index = 0;
|
||||
ctx.in_head = true;
|
||||
self.spine.push(VTag::new("thead"));
|
||||
VTag::new("tr")
|
||||
}
|
||||
Tag::TableRow => {
|
||||
let ctx = self.get_table_ctx();
|
||||
ctx.next_cell_index = 0;
|
||||
if !ctx.has_body {
|
||||
ctx.has_body = true;
|
||||
self.spine.push(VTag::new("tbody"));
|
||||
}
|
||||
VTag::new("tr")
|
||||
}
|
||||
Tag::TableCell => {
|
||||
let ctx = self.get_table_ctx();
|
||||
let idx = ctx.next_cell_index;
|
||||
ctx.next_cell_index += 1;
|
||||
|
||||
let mut tag = if ctx.in_head {
|
||||
let mut th = VTag::new("th");
|
||||
th.add_attribute("scope", "col");
|
||||
th
|
||||
} else {
|
||||
VTag::new("td")
|
||||
};
|
||||
match &ctx.alignment[idx] {
|
||||
Alignment::None => {}
|
||||
Alignment::Left => {
|
||||
tag.add_attribute("class", "text-left");
|
||||
}
|
||||
Alignment::Center => {
|
||||
tag.add_attribute("class", "text-center");
|
||||
}
|
||||
Alignment::Right => {
|
||||
tag.add_attribute("class", "text-right");
|
||||
}
|
||||
}
|
||||
tag
|
||||
}
|
||||
Tag::Emphasis => {
|
||||
let mut el = VTag::new("span");
|
||||
el.add_attribute("class", "font-italic");
|
||||
el
|
||||
}
|
||||
Tag::Strong => {
|
||||
let mut el = VTag::new("span");
|
||||
el.add_attribute("class", "font-weight-bold");
|
||||
el
|
||||
}
|
||||
Tag::Link {
|
||||
ref dest_url,
|
||||
ref title,
|
||||
link_type: _,
|
||||
id: _,
|
||||
} => {
|
||||
let mut el = VTag::new("a");
|
||||
el.add_attribute("href", dest_url.to_string());
|
||||
let title = title.clone().into_string();
|
||||
if !title.is_empty() {
|
||||
el.add_attribute("title", title);
|
||||
}
|
||||
el
|
||||
}
|
||||
Tag::Image {
|
||||
ref dest_url,
|
||||
ref title,
|
||||
link_type: _,
|
||||
id: _,
|
||||
} => {
|
||||
let mut el = VTag::new("img");
|
||||
el.add_attribute("src", dest_url.to_string());
|
||||
let title = title.clone().into_string();
|
||||
if !title.is_empty() {
|
||||
el.add_attribute("title", title);
|
||||
}
|
||||
el
|
||||
}
|
||||
Tag::FootnoteDefinition(ref _footnote_id) => VTag::new("span"), // Footnotes are not
|
||||
// rendered as anything
|
||||
// special
|
||||
Tag::Strikethrough => {
|
||||
let mut el = VTag::new("span");
|
||||
el.add_attribute("class", "text-decoration-strikethrough");
|
||||
el
|
||||
}
|
||||
Tag::HtmlBlock => VTag::new("div"),
|
||||
_ => {
|
||||
gloo::console::log!(format!("Unhandled tag: {tag:#?}"));
|
||||
VTag::new("div")
|
||||
}
|
||||
};
|
||||
self.spine.push(wrapper);
|
||||
}
|
||||
|
||||
fn end_tag(&mut self, tag: TagEnd) {
|
||||
self.pop_spine();
|
||||
match tag {
|
||||
TagEnd::CodeBlock => {
|
||||
self.pop_spine(); // Close <pre>
|
||||
}
|
||||
TagEnd::TableHead => {
|
||||
self.pop_spine(); // Close <thead>
|
||||
self.get_table_ctx().in_head = false;
|
||||
}
|
||||
TagEnd::Table => {
|
||||
let ctx = self.close_table_ctx();
|
||||
if ctx.has_body {
|
||||
self.pop_spine(); // Close <tbody>
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn write_event(&mut self, ev: Event) {
|
||||
match ev {
|
||||
Event::Start(tag) => self.start_tag(tag),
|
||||
Event::End(tag) => self.end_tag(tag),
|
||||
Event::Text(text) => self.add_child(VText::new(text.to_string()).into()),
|
||||
Event::Rule => self.add_child(VTag::new("hr").into()),
|
||||
Event::SoftBreak => self.add_child(VText::new("\n").into()),
|
||||
Event::HardBreak => self.add_child(VTag::new("br").into()),
|
||||
_ => gloo::console::log!(format!("Unhandled event: {ev:#?}")),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// Renders a string of Markdown to HTML with the default options (footnotes
|
||||
/// disabled, tables enabled).
|
||||
pub fn render_markdown(src: &str) -> Html {
|
||||
let mut elems = vec![];
|
||||
let mut spine = vec![];
|
||||
|
||||
macro_rules! add_child {
|
||||
($child:expr) => {{
|
||||
let l = spine.len();
|
||||
assert_ne!(l, 0);
|
||||
spine[l - 1].add_child($child);
|
||||
}};
|
||||
}
|
||||
let mut writer = TagWriter::new();
|
||||
|
||||
let mut options = Options::empty();
|
||||
options.insert(Options::ENABLE_TABLES);
|
||||
|
||||
for ev in Parser::new_ext(src, options) {
|
||||
match ev {
|
||||
Event::Start(tag) => {
|
||||
spine.push(make_tag(tag));
|
||||
}
|
||||
Event::End(tag) => {
|
||||
// TODO Verify stack end.
|
||||
let l = spine.len();
|
||||
assert!(l >= 1);
|
||||
let mut top = spine.pop().unwrap();
|
||||
if let Tag::CodeBlock(_) = tag {
|
||||
let mut pre = VTag::new("pre");
|
||||
pre.add_child(top.into());
|
||||
top = pre;
|
||||
} else if let Tag::Table(aligns) = tag {
|
||||
if let Some(top_children) = top.children_mut() {
|
||||
for r in top_children.to_vlist_mut().iter_mut() {
|
||||
if let VNode::VTag(ref mut vtag) = r {
|
||||
if let Some(vtag_children) = Rc::make_mut(vtag).children_mut() {
|
||||
for (i, c) in
|
||||
vtag_children.to_vlist_mut().iter_mut().enumerate()
|
||||
{
|
||||
if let VNode::VTag(ref mut vtag) = c {
|
||||
match aligns[i] {
|
||||
Alignment::None => {}
|
||||
Alignment::Left => {
|
||||
add_class(Rc::make_mut(vtag), "text-left")
|
||||
}
|
||||
Alignment::Center => {
|
||||
add_class(Rc::make_mut(vtag), "text-center")
|
||||
}
|
||||
Alignment::Right => {
|
||||
add_class(Rc::make_mut(vtag), "text-right")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if let Tag::TableHead = tag {
|
||||
if let Some(top_children) = top.children_mut() {
|
||||
for c in top_children.to_vlist_mut().iter_mut() {
|
||||
if let VNode::VTag(ref mut vtag) = c {
|
||||
// TODO
|
||||
// vtag.tag = "th".into();
|
||||
Rc::make_mut(vtag).add_attribute("scope", "col");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if l == 1 {
|
||||
elems.push(top);
|
||||
} else {
|
||||
spine[l - 2].add_child(top.into());
|
||||
}
|
||||
}
|
||||
Event::Text(text) => add_child!(VText::new(text.to_string()).into()),
|
||||
Event::Rule => add_child!(VTag::new("hr").into()),
|
||||
Event::SoftBreak => add_child!(VText::new("\n").into()),
|
||||
Event::HardBreak => add_child!(VTag::new("br").into()),
|
||||
_ => println!("Unknown event: {ev:#?}"),
|
||||
}
|
||||
writer.write_event(ev);
|
||||
}
|
||||
|
||||
if elems.len() == 1 {
|
||||
VNode::VTag(Rc::new(elems.pop().unwrap()))
|
||||
} else {
|
||||
html! {
|
||||
<div>{ for elems.into_iter() }</div>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn make_tag(t: Tag) -> VTag {
|
||||
match t {
|
||||
Tag::Paragraph => VTag::new("p"),
|
||||
Tag::Heading(n, ..) => VTag::new(n.to_string()),
|
||||
Tag::BlockQuote => {
|
||||
let mut el = VTag::new("blockquote");
|
||||
el.add_attribute("class", "blockquote");
|
||||
el
|
||||
}
|
||||
Tag::CodeBlock(code_block_kind) => {
|
||||
let mut el = VTag::new("code");
|
||||
|
||||
if let CodeBlockKind::Fenced(lang) = code_block_kind {
|
||||
// Different color schemes may be used for different code blocks,
|
||||
// but a different library (likely js based at the moment) would be necessary to
|
||||
// actually provide the highlighting support by locating the
|
||||
// language classes and applying dom transforms on their contents.
|
||||
match lang.as_ref() {
|
||||
"html" => el.add_attribute("class", "html-language"),
|
||||
"rust" => el.add_attribute("class", "rust-language"),
|
||||
"java" => el.add_attribute("class", "java-language"),
|
||||
"c" => el.add_attribute("class", "c-language"),
|
||||
_ => {} // Add your own language highlighting support
|
||||
};
|
||||
}
|
||||
|
||||
el
|
||||
}
|
||||
Tag::List(None) => VTag::new("ul"),
|
||||
Tag::List(Some(1)) => VTag::new("ol"),
|
||||
Tag::List(Some(ref start)) => {
|
||||
let mut el = VTag::new("ol");
|
||||
el.add_attribute("start", start.to_string());
|
||||
el
|
||||
}
|
||||
Tag::Item => VTag::new("li"),
|
||||
Tag::Table(_) => {
|
||||
let mut el = VTag::new("table");
|
||||
el.add_attribute("class", "table");
|
||||
el
|
||||
}
|
||||
Tag::TableHead => VTag::new("th"),
|
||||
Tag::TableRow => VTag::new("tr"),
|
||||
Tag::TableCell => VTag::new("td"),
|
||||
Tag::Emphasis => {
|
||||
let mut el = VTag::new("span");
|
||||
el.add_attribute("class", "font-italic");
|
||||
el
|
||||
}
|
||||
Tag::Strong => {
|
||||
let mut el = VTag::new("span");
|
||||
el.add_attribute("class", "font-weight-bold");
|
||||
el
|
||||
}
|
||||
Tag::Link(_link_type, ref href, ref title) => {
|
||||
let mut el = VTag::new("a");
|
||||
el.add_attribute("href", href.to_string());
|
||||
let title = title.clone().into_string();
|
||||
if !title.is_empty() {
|
||||
el.add_attribute("title", title);
|
||||
}
|
||||
el
|
||||
}
|
||||
Tag::Image(_link_type, ref src, ref title) => {
|
||||
let mut el = VTag::new("img");
|
||||
el.add_attribute("src", src.to_string());
|
||||
let title = title.clone().into_string();
|
||||
if !title.is_empty() {
|
||||
el.add_attribute("title", title);
|
||||
}
|
||||
el
|
||||
}
|
||||
Tag::FootnoteDefinition(ref _footnote_id) => VTag::new("span"), // Footnotes are not
|
||||
// rendered as anything
|
||||
// special
|
||||
Tag::Strikethrough => {
|
||||
let mut el = VTag::new("span");
|
||||
el.add_attribute("class", "text-decoration-strikethrough");
|
||||
el
|
||||
}
|
||||
}
|
||||
writer.finish()
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ edition = "2021"
|
|||
yew = { path = "../../packages/yew", features = ["csr"] }
|
||||
zxcvbn = "3.1.0"
|
||||
time = "0.3.36"
|
||||
js-sys = "0.3.64"
|
||||
js-sys = "0.3.70"
|
||||
web-sys = { version = "0.3", features = ["Event","EventTarget","InputEvent"] }
|
||||
wasm-bindgen = "0.2"
|
||||
chrono = { version = "0.4", features = ["wasmbind"] }
|
||||
|
|
|
@ -14,8 +14,8 @@ required-features = ["ssr"]
|
|||
|
||||
[dependencies]
|
||||
yew = { path = "../../packages/yew" }
|
||||
reqwest = { version = "0.12.5", features = ["json"] }
|
||||
serde = { version = "1.0.193", features = ["derive"] }
|
||||
reqwest = { version = "0.12.7", features = ["json"] }
|
||||
serde = { version = "1.0.208", features = ["derive"] }
|
||||
uuid = { version = "1.10.0", features = ["serde"] }
|
||||
futures = "0.3"
|
||||
bytes = "1.7"
|
||||
|
|
|
@ -18,7 +18,7 @@ yew = { path = "../../packages/yew" }
|
|||
function_router = { path = "../function_router" }
|
||||
log = "0.4"
|
||||
futures = { version = "0.3", features = ["std"], default-features = false }
|
||||
hyper-util = "0.1.6"
|
||||
hyper-util = "0.1.7"
|
||||
|
||||
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
||||
wasm-bindgen-futures = "0.4"
|
||||
|
@ -27,9 +27,9 @@ wasm-logger = "0.2"
|
|||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||
tokio = { version = "1.38.1", features = ["full"] }
|
||||
axum = "0.7"
|
||||
tower = { version = "0.4", features = ["make"] }
|
||||
tower = { version = "0.5", features = ["make"] }
|
||||
tower-http = { version = "0.5", features = ["fs"] }
|
||||
env_logger = "0.10"
|
||||
env_logger = "0.11"
|
||||
clap = { version = "4", features = ["derive"] }
|
||||
hyper = { version = "1.4", features = ["server", "http1"] }
|
||||
|
||||
|
|
|
@ -7,5 +7,5 @@ license = "MIT OR Apache-2.0"
|
|||
|
||||
[dependencies]
|
||||
gloo = "0.11.0"
|
||||
js-sys = "0.3.64"
|
||||
js-sys = "0.3.70"
|
||||
yew = { path = "../../packages/yew", features = ["csr"] }
|
||||
|
|
|
@ -11,4 +11,4 @@ wasm-bindgen = "0.2"
|
|||
js-sys = "0.3"
|
||||
web-sys = { version = "0.3", features = [ "HtmlInputElement" ] }
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
postcard = "1.0.8"
|
||||
postcard = "1.0.10"
|
||||
|
|
|
@ -8,4 +8,4 @@ yew-agent = { path = "../../packages/yew-agent" }
|
|||
yew = { path = "../../packages/yew", features = ["csr"] }
|
||||
futures = "0.3.30"
|
||||
primes = "0.4.0"
|
||||
serde = { version = "1.0.193", features = ["derive"] }
|
||||
serde = { version = "1.0.208", features = ["derive"] }
|
||||
|
|
|
@ -20,4 +20,4 @@ futures = "0.3"
|
|||
yew-agent-macro = { version = "0.2", path = "../yew-agent-macro" }
|
||||
|
||||
[dev-dependencies]
|
||||
serde = "1.0.193"
|
||||
serde = "1.0.208"
|
||||
|
|
|
@ -68,10 +68,10 @@ fn const_generics<const N: ::std::primitive::i32>() -> ::yew::Html {
|
|||
}
|
||||
|
||||
fn compile_pass() {
|
||||
::yew::html! { <Comp<Props> a=10 /> };
|
||||
::yew::html! { <Comp1<::std::primitive::usize, ::std::primitive::usize> /> };
|
||||
let _ = ::yew::html! { <Comp<Props> a=10 /> };
|
||||
let _ = ::yew::html! { <Comp1<::std::primitive::usize, ::std::primitive::usize> /> };
|
||||
|
||||
::yew::html! { <ConstGenerics<10> /> };
|
||||
let _ = ::yew::html! { <ConstGenerics<10> /> };
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
@ -11,7 +11,7 @@ pub trait MyTrait {
|
|||
|
||||
#[yew::hook]
|
||||
pub fn use_query_state<Props>(
|
||||
selector: impl yew::html::IntoPropValue<bool>,
|
||||
_selector: impl yew::html::IntoPropValue<bool>,
|
||||
) -> QueryState<Props::Associated>
|
||||
where
|
||||
Props: MyTrait,
|
||||
|
|
|
@ -4,7 +4,7 @@ error: only one root html element is allowed (hint: you can wrap multiple html e
|
|||
4 | html! { "valid" "invalid" };
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: unexpected token
|
||||
error: unexpected token, expected `}`
|
||||
--> tests/html_macro/node-fail.rs:5:29
|
||||
|
|
||||
5 | html! { <span>{ "valid" "invalid" }</span> };
|
||||
|
|
|
@ -43,7 +43,7 @@ wasm-bindgen-futures = "0.4"
|
|||
tokio = { version = "1.38", features = ["rt"] }
|
||||
|
||||
[dependencies.web-sys]
|
||||
version = "^0.3.69"
|
||||
version = "^0.3.70"
|
||||
features = [
|
||||
"AnimationEvent",
|
||||
"Document",
|
||||
|
|
|
@ -152,8 +152,9 @@ impl EventListener {
|
|||
|
||||
let callback = Closure::wrap(Box::new(callback) as Box<dyn Fn(&Event)>);
|
||||
// defaults: { once: false }
|
||||
let mut options = AddEventListenerOptions::new();
|
||||
options.capture(true).passive(desc.passive);
|
||||
let options = AddEventListenerOptions::new();
|
||||
options.set_capture(true);
|
||||
options.set_passive(desc.passive);
|
||||
|
||||
target
|
||||
.add_event_listener_with_callback_and_add_event_listener_options(
|
||||
|
|
|
@ -9,9 +9,9 @@ crate-type = ["cdylib"]
|
|||
|
||||
[dependencies]
|
||||
rand = { version = "0.8.5", features = ["small_rng"] }
|
||||
getrandom = { version = "0.2.14", features = ["js"] }
|
||||
getrandom = { version = "0.2.15", features = ["js"] }
|
||||
wasm-bindgen = "0.2.92"
|
||||
web-sys = { version = "0.3.69", features = ["Window"]}
|
||||
web-sys = { version = "0.3.70", features = ["Window"]}
|
||||
yew = { version = "0.21.0", features = ["csr"], path = "../../packages/yew" }
|
||||
|
||||
[package.metadata.wasm-pack.profile.release]
|
||||
|
|
|
@ -10,9 +10,9 @@ yew = { path = "../../packages/yew", features = ["ssr"] }
|
|||
function_router = { path = "../../examples/function_router" }
|
||||
tokio = { version = "1.38", features = ["full"] }
|
||||
average = "0.15.1"
|
||||
tabled = "0.15.0"
|
||||
tabled = "0.16.0"
|
||||
indicatif = "0.17.8"
|
||||
serde = { version = "1.0.193", features = ["derive"] }
|
||||
serde = { version = "1.0.208", features = ["derive"] }
|
||||
serde_json = "1.0.109"
|
||||
clap = { version = "4", features = ["derive"] }
|
||||
|
||||
|
|
|
@ -9,9 +9,9 @@ crate-type = ["cdylib"]
|
|||
|
||||
[dependencies]
|
||||
rand = { version = "0.8.5", features = ["small_rng"] }
|
||||
getrandom = { version = "0.2.14", features = ["js"] }
|
||||
getrandom = { version = "0.2.15", features = ["js"] }
|
||||
wasm-bindgen = "0.2.92"
|
||||
web-sys = { version = "0.3.69", features = ["Window"]}
|
||||
web-sys = { version = "0.3.70", features = ["Window"]}
|
||||
yew = { version = "0.21.0", features = ["csr"], path = "../../packages/yew" }
|
||||
|
||||
[package.metadata.wasm-pack.profile.release]
|
||||
|
|
|
@ -10,7 +10,7 @@ rust-version = "1.62"
|
|||
yew-agent = { path = "../../packages/yew-agent/" }
|
||||
|
||||
[dev-dependencies]
|
||||
derive_more = "0.99"
|
||||
derive_more = { version = "1.0", features = ["from"] }
|
||||
gloo = "0.11"
|
||||
js-sys = "0.3"
|
||||
wasm-bindgen = "0.2"
|
||||
|
|
Loading…
Reference in New Issue