MichaelHatherly / CommonMark.jl

A CommonMark-compliant Markdown parser for Julia.
Other
87 stars 11 forks source link

Markdown printing adds unwanted newlines #43

Open domluna opened 2 years ago

domluna commented 2 years ago

ref https://github.com/domluna/JuliaFormatter.jl/issues/603

Wondering if there's a way to disable this behaviour

julia> s = """
       \"\"\"
           solve_knapsack(
               optimizer,
               data_filename::String,
               config::_AbstractConfiguration,
           )

       Solve the knapsack problem and return the optimal primal solution

       ## Arguments

         - `optimizer`: an object that can be passed to `JuMP.Model` to construct a new
           JuMP model.
         - `data_filename`: the filename of a JSON file containing the data for the
           problem.
         - `config`: an object to control the type of knapsack model constructed.
           Valid options are:
             + `BinaryKnapsackConfig()`
             + `IntegerKnapsackConfig()`

       ## Returns
       \"\"\"
       foo() = nothing
       """
"\"\"\"\n    solve_knapsack(\n        optimizer,\n        data_filename::String,\n        config::_AbstractConfiguration,\n    )\n\nSolve the knapsack problem and return the optimal primal solution\n\n## Arguments\n\n  - `optimizer`: an object that can be passed to `JuMP.Model` to construct a new\n    JuMP model.\n  - `data_filename`: the filename of a JSON file containing the data for the\n    problem.\n  - `config`: an object to control the type of knapsack model constructed.\n    Valid options are:\n      + `BinaryKnapsackConfig()`\n      + `IntegerKnapsackConfig()`\n\n## Returns\n\"\"\"\nfoo() = nothing\n"

julia> parser = Parser()
Parser(Node(CommonMark.Document))

julia> ast = parser(s)
 """ solve_knapsack( optimizer, data_filename::String, config::_AbstractConfiguration, )

 Solve the knapsack problem and return the optimal primal solution

 ## Arguments

  ● optimizer: an object that can be passed to JuMP.Model to construct a new JuMP model.

  ● data_filename: the filename of a JSON file containing the data for the problem.

  ● config: an object to control the type of knapsack model constructed. Valid options are:

     ○ BinaryKnapsackConfig()

     ○ IntegerKnapsackConfig()

 ## Returns

 """ foo() = nothing

julia> markdown(ast) |> print
"""
solve_knapsack(
optimizer,
data_filename::String,
config::_AbstractConfiguration,
)

Solve the knapsack problem and return the optimal primal solution

## Arguments

  - `optimizer`: an object that can be passed to `JuMP.Model` to construct a new
    JuMP model.
  - `data_filename`: the filename of a JSON file containing the data for the
    problem.
  - `config`: an object to control the type of knapsack model constructed.
    Valid options are:

      + `BinaryKnapsackConfig()`
      + `IntegerKnapsackConfig()`

## Returns

"""
foo() = nothing

julia>

If I assign the result of markdown printing to another variable and try it again it produces another newline

julia> markdown(ast) |> print
"""
solve_knapsack(
optimizer,
data_filename::String,
config::_AbstractConfiguration,
)

Solve the knapsack problem and return the optimal primal solution

## Arguments

  - `optimizer`: an object that can be passed to `JuMP.Model` to construct a new
    JuMP model.

  - `data_filename`: the filename of a JSON file containing the data for the
    problem.
  - `config`: an object to control the type of knapsack model constructed.
    Valid options are:

      + `BinaryKnapsackConfig()`
      + `IntegerKnapsackConfig()`

## Returns

"""
foo() = nothing

At this point no new newlines are added.

domluna commented 2 years ago

@MichaelHatherly is there a way to not alter the markdown at all? So essentially just modify Julia specific code blocks and keep the rest of the file intact.