-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for serializing mdast as markdown
Closes GH-64. Closes GH-127. Reviewed-by: Titus Wormer <[email protected]>
- Loading branch information
Showing
66 changed files
with
8,324 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
name = "mdast_util_to_markdown" | ||
version = "0.0.0" | ||
edition = "2018" | ||
license = "MIT" | ||
|
||
[dependencies] | ||
markdown = { path = "../" } | ||
regex = { version = "1" } | ||
|
||
[dev-dependencies] | ||
pretty_assertions = { workspace = true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use alloc::string::String; | ||
use markdown::mdast::{Definition, ImageReference, LinkReference}; | ||
|
||
pub trait Association { | ||
fn identifier(&self) -> &String; | ||
fn label(&self) -> &Option<String>; | ||
} | ||
|
||
impl Association for Definition { | ||
fn identifier(&self) -> &String { | ||
&self.identifier | ||
} | ||
|
||
fn label(&self) -> &Option<String> { | ||
&self.label | ||
} | ||
} | ||
|
||
impl Association for ImageReference { | ||
fn identifier(&self) -> &String { | ||
&self.identifier | ||
} | ||
|
||
fn label(&self) -> &Option<String> { | ||
&self.label | ||
} | ||
} | ||
|
||
impl Association for LinkReference { | ||
fn identifier(&self) -> &String { | ||
&self.identifier | ||
} | ||
|
||
fn label(&self) -> &Option<String> { | ||
&self.label | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
pub struct Options { | ||
/// Marker to use for bullets of items in unordered lists ('*', '+', or '-', default: '*'). | ||
pub bullet: char, | ||
// Marker to use in certain cases where the primary bullet doesn’t work | ||
// ('*', '+', or '-', default: '-' when bullet is '*', '*' otherwise). | ||
pub bullet_other: char, | ||
/// Marker to use for bullets of items in ordered lists ('.' or ')', default: '.'). | ||
pub bullet_ordered: char, | ||
/// Marker to use for emphasis ('*' or '_', default: '*'). | ||
pub emphasis: char, | ||
// Marker to use for fenced code ('`' or '~', default: '`'). | ||
pub fence: char, | ||
/// Whether to use fenced code always (bool, default: true). The default is to use fenced code | ||
/// if there is a language defined, if the code is empty, or if it starts or ends in blank lines. | ||
pub fences: bool, | ||
// How to indent the content of list items (default: 'IndentOptions::One'). | ||
pub list_item_indent: IndentOptions, | ||
/// Marker to use for titles ('"' or "'", default: '"'). | ||
pub quote: char, | ||
/// Marker to use for thematic breaks ('*', '-', or '_', default: '*'). | ||
pub rule: char, | ||
// Marker to use for strong ('*' or '_', default: '*'). | ||
pub strong: char, | ||
// Whether to increment the counter of ordered lists items (bool, default: true). | ||
pub increment_list_marker: bool, | ||
/// Whether to add the same number of number signs (#) at the end of an ATX heading as the | ||
/// opening sequence (bool, default: false). | ||
pub close_atx: bool, | ||
/// Whether to always use resource links (bool, default: false). The default is to use autolinks | ||
/// (<https://example.com>) when possible and resource links ([text](url)) otherwise. | ||
pub resource_link: bool, | ||
/// Whether to add spaces between markers in thematic breaks (bool, default: false). | ||
pub rule_spaces: bool, | ||
/// Whether to use setext headings when possible (bool, default: false). The default is to always | ||
/// use ATX headings (# heading) instead of setext headings (heading\n=======). Setext headings | ||
/// cannot be used for empty headings or headings with a rank of three or more. | ||
pub setext: bool, | ||
/// Whether to join definitions without a blank line (bool, default: false). | ||
pub tight_definitions: bool, | ||
// Number of markers to use for thematic breaks (u32, default: 3, min: 3). | ||
pub rule_repetition: u32, | ||
} | ||
|
||
#[derive(Copy, Clone)] | ||
pub enum IndentOptions { | ||
// Depends on the item and its parent list uses 'One' if the item and list are tight and 'Tab' | ||
// otherwise. | ||
Mixed, | ||
// The size of the bullet plus one space. | ||
One, | ||
/// Tab stop. | ||
Tab, | ||
} | ||
|
||
impl Default for Options { | ||
fn default() -> Self { | ||
Self { | ||
bullet: '*', | ||
bullet_other: '-', | ||
bullet_ordered: '.', | ||
emphasis: '*', | ||
fence: '`', | ||
fences: true, | ||
increment_list_marker: true, | ||
rule_repetition: 3, | ||
list_item_indent: IndentOptions::One, | ||
quote: '"', | ||
rule: '*', | ||
strong: '*', | ||
close_atx: false, | ||
rule_spaces: false, | ||
resource_link: false, | ||
setext: false, | ||
tight_definitions: false, | ||
} | ||
} | ||
} |
Oops, something went wrong.