Skip to content

Commit e7ed526

Browse files
committed
Refactor code style, add links to js versions
1 parent 567e7e0 commit e7ed526

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+894
-876
lines changed

.github/workflows/main.yml

+12-13
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
1-
name: main
2-
on:
3-
- pull_request
4-
- push
51
jobs:
6-
main:
2+
coverage:
73
runs-on: ubuntu-latest
84
steps:
95
- uses: actions/checkout@v4
106
- uses: dtolnay/rust-toolchain@v1
117
with:
128
toolchain: stable
13-
components: rustfmt, clippy
14-
- run: cargo fmt --check && cargo clippy --examples --tests --benches --all-features
15-
- run: cargo test --all-features
16-
- run: cargo clippy -p mdast_util_to_markdown
17-
- run: cargo test -p mdast_util_to_markdown
18-
coverage:
9+
- run: cargo install cargo-tarpaulin
10+
- run: cargo tarpaulin --features json --out xml
11+
- uses: codecov/codecov-action@v4
12+
main:
1913
runs-on: ubuntu-latest
2014
steps:
2115
- uses: actions/checkout@v4
2216
- uses: dtolnay/rust-toolchain@v1
2317
with:
18+
components: clippy, rustfmt
2419
toolchain: stable
25-
- run: cargo install cargo-tarpaulin && cargo tarpaulin --features json --out xml
26-
- uses: codecov/codecov-action@v4
20+
- run: cargo fmt --check && cargo clippy --all-features --all-targets --workspace
21+
- run: cargo test --all-features --workspace
22+
name: main
23+
on:
24+
- pull_request
25+
- push

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
*.log
33
*.lock
44
coverage/
5-
target
5+
target/
66
commonmark-data.txt
77
unicode-data.txt
88
fuzz/target

Cargo.toml

+33-33
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,47 @@
1-
[package]
2-
name = "markdown"
3-
version = "1.0.0-alpha.21"
4-
authors = ["Titus Wormer <[email protected]>"]
5-
edition = "2018"
6-
rust-version = "1.56"
7-
description = "CommonMark compliant markdown parser in Rust with ASTs and extensions"
8-
homepage = "https://github.com/wooorm/markdown-rs"
9-
repository = "https://github.com/wooorm/markdown-rs"
10-
license = "MIT"
11-
keywords = ["commonmark", "markdown", "parse", "render", "tokenize"]
12-
categories = ["compilers", "encoding", "parser-implementations", "parsing", "text-processing"]
13-
include = ["src/", "license"]
14-
15-
[workspace]
16-
members = ["generate", "mdast_util_to_markdown"]
17-
18-
[workspace.dependencies]
19-
pretty_assertions = "1"
20-
211
[[bench]]
2+
harness = false
223
name = "bench"
234
path = "benches/bench.rs"
24-
harness = false
25-
26-
[features]
27-
default = []
28-
json = ["serde"]
29-
serde = ["dep:serde"]
30-
log = ["dep:log"]
315

326
[dependencies]
33-
log = { version = "0.4", optional = true }
34-
unicode-id = { version = "0.3", features = ["no_std"] }
35-
serde = { version = "1", features = ["derive"], optional = true }
7+
log = { optional = true, version = "0.4" }
8+
serde = { features = ["derive"], optional = true, version = "1" }
9+
unicode-id = { features = ["no_std"], version = "0.3" }
3610

3711
[dev-dependencies]
38-
env_logger = "0.11"
3912
criterion = "0.5"
13+
env_logger = "0.11"
4014
pretty_assertions = { workspace = true }
4115
serde_json = { version = "1" }
4216
swc_core = { version = "0.100", features = [
17+
"common",
4318
"ecma_ast",
44-
"ecma_visit",
4519
"ecma_parser",
46-
"common",
20+
"ecma_visit",
4721
] }
22+
23+
[features]
24+
default = []
25+
json = ["serde"]
26+
log = ["dep:log"]
27+
serde = ["dep:serde"]
28+
29+
[package]
30+
authors = ["Titus Wormer <[email protected]>"]
31+
categories = ["compilers", "encoding", "parser-implementations", "parsing", "text-processing"]
32+
description = "CommonMark compliant markdown parser in Rust with ASTs and extensions"
33+
edition = "2018"
34+
homepage = "https://github.com/wooorm/markdown-rs"
35+
include = ["src/", "license"]
36+
keywords = ["commonmark", "markdown", "parse", "render", "tokenize"]
37+
license = "MIT"
38+
name = "markdown"
39+
repository = "https://github.com/wooorm/markdown-rs"
40+
rust-version = "1.56"
41+
version = "1.0.0-alpha.21"
42+
43+
[workspace]
44+
members = ["generate", "mdast_util_to_markdown"]
45+
46+
[workspace.dependencies]
47+
pretty_assertions = "1"

generate/Cargo.toml

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
[dependencies]
2+
regex = "1"
3+
reqwest = "0.12"
4+
tokio = { features = ["full"], version = "1" }
5+
16
[package]
2-
name = "markdown-generate"
3-
version = "0.0.0"
47
authors = ["Titus Wormer <[email protected]>"]
58
edition = "2018"
9+
name = "markdown-generate"
610
publish = false
7-
8-
[dependencies]
9-
regex = "1"
10-
reqwest = "0.12"
11-
tokio = { version = "1", features = ["full"] }
11+
version = "0.0.0"

mdast_util_to_markdown/Cargo.toml

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
[package]
2-
name = "mdast_util_to_markdown"
3-
version = "0.0.0"
4-
edition = "2018"
5-
license = "MIT"
6-
71
[dependencies]
82
markdown = { path = "../" }
93
regex = { version = "1" }
104

115
[dev-dependencies]
126
pretty_assertions = { workspace = true }
7+
8+
[package]
9+
edition = "2018"
10+
license = "MIT"
11+
name = "mdast_util_to_markdown"
12+
version = "0.0.0"

mdast_util_to_markdown/src/association.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
//! Traits for <https://github.com/syntax-tree/mdast#association>.
2+
//!
3+
//! JS equivalent: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/70e1a4f/types/mdast/index.d.ts#L48.
4+
15
use alloc::string::String;
26
use markdown::mdast::{Definition, ImageReference, LinkReference};
37

mdast_util_to_markdown/src/configure.rs

+65-45
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,96 @@
1+
//! Configuration.
2+
//!
3+
//! JS equivalent: https://github.com/syntax-tree/mdast-util-to-markdown/blob/fd6a508/lib/types.js#L307.
4+
5+
#[derive(Clone, Copy)]
6+
/// Configuration for indent of lists.
7+
pub enum IndentOptions {
8+
/// Depends on the item and its parent list: uses `IndentOptions::One` if
9+
/// the item and list are tight and `IndentOptions::Tab` otherwise.
10+
Mixed,
11+
/// The size of the bullet plus one space.
12+
One,
13+
/// Tab stop.
14+
Tab,
15+
}
16+
17+
/// Configuration.
118
pub struct Options {
2-
/// Marker to use for bullets of items in unordered lists ('*', '+', or '-', default: '*').
19+
/// Marker to use for bullets of items in unordered lists (`'*'`, `'+'`, or
20+
/// `'-'`, default: `'*'`).
321
pub bullet: char,
4-
// Marker to use in certain cases where the primary bullet doesn’t work
5-
// ('*', '+', or '-', default: '-' when bullet is '*', '*' otherwise).
6-
pub bullet_other: char,
7-
/// Marker to use for bullets of items in ordered lists ('.' or ')', default: '.').
22+
/// Marker to use for bullets of items in ordered lists (`'.'` or `')'`,
23+
/// default: `'.'`).
824
pub bullet_ordered: char,
9-
/// Marker to use for emphasis ('*' or '_', default: '*').
25+
/// Marker to use in certain cases where the primary bullet doesn’t work
26+
/// (`'*'`, `'+'`, or `'-'`, default: `'-'` when bullet is `'*'`, `'*'`
27+
/// otherwise).
28+
pub bullet_other: char,
29+
/// Whether to add the same number of number signs (`#`) at the end of an
30+
/// ATX heading as the opening sequence (`bool`, default: `false`).
31+
pub close_atx: bool,
32+
/// Marker to use for emphasis (`'*'` or `'_'`, default: `'*'`).
1033
pub emphasis: char,
11-
// Marker to use for fenced code ('`' or '~', default: '`').
34+
/// Marker to use for fenced code (``'`'`` or `'~'`, default: ``'`'``).
1235
pub fence: char,
13-
/// Whether to use fenced code always (bool, default: true). The default is to use fenced code
14-
/// if there is a language defined, if the code is empty, or if it starts or ends in blank lines.
36+
/// Whether to use fenced code always (`bool`, default: `true`).
37+
/// The default is to use fenced code if there is a language defined,
38+
/// if the code is empty,
39+
/// or if it starts or ends in blank lines.
1540
pub fences: bool,
16-
// How to indent the content of list items (default: 'IndentOptions::One').
41+
/// Whether to increment the counter of ordered lists items (`bool`,
42+
/// default: `true`).
43+
pub increment_list_marker: bool,
44+
/// How to indent the content of list items (default: `IndentOptions::One`).
1745
pub list_item_indent: IndentOptions,
18-
/// Marker to use for titles ('"' or "'", default: '"').
46+
/// Marker to use for titles (`'"'` or `"'"`, default: `'"'`).
1947
pub quote: char,
20-
/// Marker to use for thematic breaks ('*', '-', or '_', default: '*').
21-
pub rule: char,
22-
// Marker to use for strong ('*' or '_', default: '*').
23-
pub strong: char,
24-
// Whether to increment the counter of ordered lists items (bool, default: true).
25-
pub increment_list_marker: bool,
26-
/// Whether to add the same number of number signs (#) at the end of an ATX heading as the
27-
/// opening sequence (bool, default: false).
28-
pub close_atx: bool,
29-
/// Whether to always use resource links (bool, default: false). The default is to use autolinks
30-
/// (<https://example.com>) when possible and resource links ([text](url)) otherwise.
48+
/// Whether to always use resource links (`bool`, default: `false`).
49+
/// The default is to use autolinks (`<https://example.com>`) when possible
50+
/// and resource links (`[text](url)`) otherwise.
3151
pub resource_link: bool,
32-
/// Whether to add spaces between markers in thematic breaks (bool, default: false).
52+
/// Marker to use for thematic breaks (`'*'`, `'-'`, or `'_'`, default:
53+
/// `'*'`).
54+
pub rule: char,
55+
/// Number of markers to use for thematic breaks (`u32`, default: `3`, min:
56+
/// `3`).
57+
pub rule_repetition: u32,
58+
/// Whether to add spaces between markers in thematic breaks (`bool`,
59+
/// default: `false`).
3360
pub rule_spaces: bool,
34-
/// Whether to use setext headings when possible (bool, default: false). The default is to always
35-
/// use ATX headings (# heading) instead of setext headings (heading\n=======). Setext headings
36-
/// cannot be used for empty headings or headings with a rank of three or more.
61+
/// Whether to use setext headings when possible (`bool`, default:
62+
/// `false`).
63+
/// The default is to always use ATX headings (`# heading`) instead of
64+
/// setext headings (`heading\n=======`).
65+
/// Setext headings cannot be used for empty headings or headings with a
66+
/// rank of three or more.
3767
pub setext: bool,
38-
/// Whether to join definitions without a blank line (bool, default: false).
68+
/// Marker to use for strong (`'*'` or `'_'`, default: `'*'`).
69+
pub strong: char,
70+
/// Whether to join definitions without a blank line (`bool`, default:
71+
/// `false`).
3972
pub tight_definitions: bool,
40-
// Number of markers to use for thematic breaks (u32, default: 3, min: 3).
41-
pub rule_repetition: u32,
42-
}
43-
44-
#[derive(Copy, Clone)]
45-
pub enum IndentOptions {
46-
// Depends on the item and its parent list uses 'One' if the item and list are tight and 'Tab'
47-
// otherwise.
48-
Mixed,
49-
// The size of the bullet plus one space.
50-
One,
51-
/// Tab stop.
52-
Tab,
5373
}
5474

5575
impl Default for Options {
5676
fn default() -> Self {
5777
Self {
5878
bullet: '*',
59-
bullet_other: '-',
6079
bullet_ordered: '.',
80+
bullet_other: '-',
81+
close_atx: false,
6182
emphasis: '*',
6283
fence: '`',
6384
fences: true,
6485
increment_list_marker: true,
65-
rule_repetition: 3,
6686
list_item_indent: IndentOptions::One,
6787
quote: '"',
88+
resource_link: false,
6889
rule: '*',
69-
strong: '*',
70-
close_atx: false,
90+
rule_repetition: 3,
7191
rule_spaces: false,
72-
resource_link: false,
7392
setext: false,
93+
strong: '*',
7494
tight_definitions: false,
7595
}
7696
}

0 commit comments

Comments
 (0)