Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ criterion = "0.5"
env_logger = "0.11"
pretty_assertions = { workspace = true }
serde_json = { version = "1" }
swc_core = { version = "22", features = [
swc_core = { version = "32", features = [
"common",
"ecma_ast",
"ecma_parser",
Expand Down
39 changes: 39 additions & 0 deletions src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,45 @@ pub struct CompileOptions {
/// * [*§ 6.1 Disallowed Raw HTML (extension)* in GFM](https://github.github.com/gfm/#disallowed-raw-html-extension-)
/// * [`cmark-gfm#extensions/tagfilter.c`](https://github.com/github/cmark-gfm/blob/master/extensions/tagfilter.c)
pub gfm_tagfilter: bool,

/// Whether to not use `<p>` elements to surround free text
///
/// The default is `false`
///
/// ## Examples
///
/// ```
/// use markdown::{to_html_with_options, CompileOptions, Options, ParseOptions};
/// # fn main() -> Result<(), markdown::message::Message> {
///
/// // With `no_paragraphs` set to `false`, normal text is surrounded with `<p>` elements
/// assert_eq!(
/// to_html_with_options(
/// "Hello",
/// &Options::default(),
/// )?,
/// "<p>Hello</p>"
/// );
///
/// // Pass `no_paragraphs: true` to remove them
/// assert_eq!(
/// to_html_with_options(
/// "Hello",
/// &Options {
/// parse: ParseOptions::default(),
/// compile: CompileOptions {
/// no_paragraphs: true,
/// ..CompileOptions::default()
/// }
/// }
/// )?,
/// "Hello"
/// );
/// # Ok(())
/// # }
/// ```
///
pub no_paragraphs: bool,
}

impl CompileOptions {
Expand Down
4 changes: 2 additions & 2 deletions src/to_html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ fn on_enter_list_item_marker(context: &mut CompileContext) {
fn on_enter_paragraph(context: &mut CompileContext) {
let tight = context.tight_stack.last().unwrap_or(&false);

if !tight {
if !tight && !context.options.no_paragraphs {
context.line_ending_if_needed();
context.push("<p>");
}
Expand Down Expand Up @@ -1519,7 +1519,7 @@ fn on_exit_media(context: &mut CompileContext) {
fn on_exit_paragraph(context: &mut CompileContext) {
let tight = context.tight_stack.last().unwrap_or(&false);

if *tight {
if *tight || context.options.no_paragraphs {
context.slurp_one_line_ending = true;
} else {
context.push("</p>");
Expand Down
4 changes: 2 additions & 2 deletions tests/mdx_expression_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ fn mdx_expression() -> Result<(), message::Message> {
.err()
.unwrap()
.to_string(),
"2:8: Could not parse expression with swc: Unexpected eof (mdx:swc)",
"2:8: Could not parse expression with swc: Expression expected (mdx:swc)",
"should crash on incorrect expressions in containers (1)"
);

Expand Down Expand Up @@ -270,7 +270,7 @@ fn mdx_expression_text_gnostic() -> Result<(), message::Message> {
.err()
.unwrap()
.to_string(),
"1:9: Could not parse expression with swc: Unexpected eof (mdx:swc)",
"1:9: Could not parse expression with swc: Expression expected (mdx:swc)",
"should crash on an incorrect expression"
);

Expand Down
2 changes: 1 addition & 1 deletion tests/test_utils/swc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ fn create_config(source: String) -> (SourceFile, Syntax, EsVersion) {
FileName::Anon.into(),
false,
FileName::Anon.into(),
source,
source.into(),
BytePos::from_usize(1),
),
// Syntax.
Expand Down