Skip to content

Conversation

@basebox-mt
Copy link

This PR contains Markdown usage samples in the documentation and the examples folder as well as some opinionated fixes to the Markdown handling itself:

  • All headings are rendered in bold font, no matter what level
  • Blockquotes are rendered in italic with a single leading > for easier soft line breaks
  • Never allows more than one blank line
  • Inserts one blank line before and after headings, code blocks, blockquotes

The parsing test has been changed to make it easier to find the failing span; it has also been extended to test the new behaviour.

pulldown-cmark seems to have a bug that always returns an empty title for links. I updated it to version 0.13 in Cargo.toml, but this unfortunately did not change this.

//! ### Examples
//!
//! ```rust
//! use cursive::utils::markup::markdown::parse;
Copy link
Owner

@gyscos gyscos Apr 5, 2025

Choose a reason for hiding this comment

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

You might need extern crate cursive_core as cursive;, so it really just needs cursive_core, but it looks as cursive for users.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks - strange though that I cannot reproduce this locally. I'll try.

Copy link
Owner

Choose a reason for hiding this comment

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

You'll need to test with the markdown feature to run these

Copy link
Author

Choose a reason for hiding this comment

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

Got it, now I can at least reproduce

Copy link
Author

Choose a reason for hiding this comment

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

Can't seem to fix it... it cannot resolve CursiveExt, and when I remove it, the compiler can't find the run() method.

Copy link
Author

Choose a reason for hiding this comment

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

CursiveExt is in a different crate, this might just not be possible. If it's ok I remove the example in the doc comment. I put an Markdown example into the examples folder.

Copy link
Owner

Choose a reason for hiding this comment

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

You also don't need to run the cursive app (or even make one), you can focus on parsing the markdown and building the TextView

@basebox-mt
Copy link
Author

I set the example in the doc comment to "ignore" - let me know if that's ok for you or of course feel free to change.

@basebox-mt
Copy link
Author

Are there issues with this PR that prevent merge?

@gyscos
Copy link
Owner

gyscos commented Jul 25, 2025

Sorry, just have been very busy. Will hopefully have some time to get back in the coming weeks.

parser: pulldown_cmark::Parser<'a>,
/// In a code block, we keep newlines.
in_codeblock: bool,
/// Just added a new paragrap (\n\n)
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
/// Just added a new paragrap (\n\n)
/// Just added a new paragraph (\n\n)

self.stack.push(Style::from(Effect::Italic));
/* Force a blank line before a blockquote */
self.new_paragraph = true;
return Some(self.literal("\n\n> "));
Copy link
Owner

Choose a reason for hiding this comment

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

Should we still insert 2 newlines, even if this is the first thing in the document?

* render an Autlink instead of an Inline link.
*/
return if title.is_empty() {
Some(self.literal(format!("<{dest_url}> ")))
Copy link
Owner

Choose a reason for hiding this comment

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

Does it include a trailing space on purpose? If so, let's add a comment to make it clear.

Comment on lines +360 to +369
Span {
content: "<https://en.wikipedia.org> ",
width: "<https://en.wikipedia.org> ".width(),
attr: &style_none,
},
Span {
content: "Link",
width: "Link".width(),
attr: &style_none,
},
Copy link
Owner

Choose a reason for hiding this comment

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

Does that mean [link](url) is rendered <url> link? Is that the intended behavior?

Comment on lines +370 to +379
Span {
content: "\n\n",
width: "\n\n".width(),
attr: &style_none,
},
Span {
content: "\n\n",
width: "\n\n".width(),
attr: &style_none,
},
Copy link
Owner

Choose a reason for hiding this comment

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

4 new lines at the end of the doc? Maybe we could avoid that.

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