-
-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Serialize mdast to markdown #127
Merged
Merged
Changes from all commits
Commits
Show all changes
74 commits
Select commit
Hold shift + click to select a range
973f760
init mdast to markdown
bnchi 691bb87
Handle texts in a simple way
bnchi b2a2ed3
Add container phrasing
bnchi 25ee1b6
Fix minor typo
bnchi 4ff2d02
Change comment
bnchi 06e89f5
Update comment
bnchi 78e6529
Add support for flow containers and default joins
bnchi 9e5e9be
Add parents macro
bnchi 21486d1
rename join default
bnchi 66885de
Add unsafe
bnchi 0733560
Fix typo
bnchi 41d01f1
Make it safe
bnchi dd44b06
Fix clippy issues
bnchi dae7d26
Reduce some of the allocations
bnchi b598a26
Make things less pub for now
bnchi e9991fd
Move mdast to md into a workspace
bnchi 558b316
A few refactors for parent nodes abstraction
bnchi 973de93
Refactor
bnchi 98243d3
Add support with tests for strong, paragraph and text
bnchi 8e2055a
Add support for emphasis
bnchi 0d939d1
Fix minor bug
bnchi 3072d02
Add support for heading and break
bnchi 464f327
Refactor compile pattern
bnchi e94d898
More refactor for compile pattern
bnchi 3d1a896
Make inde_stack usize
bnchi 16a3cb0
Add support for html
bnchi b9752b7
Fix minor bug in html
bnchi a8a2351
Add valid expected unwraps
bnchi c1e3758
Fix typos
bnchi 4bf37ce
Add support for thematic break
bnchi 67aa7ee
Add support for code
bnchi b542777
Add support for blockquote without full tests support
bnchi 4969d1a
Add support for list and list item
bnchi 04fb9e0
Add support for image
bnchi 7ff2abb
Add support for link
bnchi 3fa6bd2
Depend on Regex less in some trivial code
bnchi 66f5024
Few updates
bnchi 9b03c74
Add support for inline code
bnchi c43f209
Add support for root
bnchi f3efe18
Update break comment
bnchi 8d34b35
Add support for definition
bnchi e062d85
make markdown utils pub
bnchi 2b22136
Change util visibility and make decode_named and decode_numeric pub
bnchi ff30eb1
Refactor association
bnchi 9c5e808
Update the name of the association mod
bnchi 58ff3b8
Add support for image reference
bnchi f512a4c
merge
bnchi 250a6cd
Update blockquote
bnchi 04bdc71
Add support for link reference
bnchi 7596d29
Fix typo
bnchi 3eef67f
Refactor
bnchi ddde5b4
Add support for tight defs and few refactors
bnchi 51bb56a
Refactor join
bnchi 8ff33fd
Refactor message
bnchi 216ffd6
Update the message source
bnchi 088fd7a
Add more blockquote tests
bnchi bc509ea
Complete blockquote tests
bnchi 9bfa391
Add tests for list item
bnchi a288baa
Minor refactor
bnchi 3312e38
Update CI jobs
bnchi 2262c6e
Complete the tests for list_item
bnchi 0785d36
Change comment
bnchi 65751f8
Add tests for core
bnchi cfc6963
fix few test assertion message
bnchi aced8d4
Fix minor typo in bullet other check
bnchi ff12c7b
Add roundtrip tests
bnchi 7786144
Update remove_pos
bnchi 76f182f
Remove duplicate test
bnchi 487225a
Minor refactor for list_item
bnchi cb4c81e
Fix typo
bnchi 5faeb16
Add comments
bnchi c83247d
Add comments for construct names
bnchi 82d8d90
Update comments
bnchi c73a56b
Update comments wrapping
bnchi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs some docs. Could be taken from
mdast-util-to-markdown
as well. See core ofmarkdown-rs
for info on how to do docs.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added comments here let me know if that's good enough