Skip to content

@md_str parses underscores in interpolated variables (Markdown.jl) #57265

Open
@abhro

Description

@abhro

If there is an unescaped underscore in the string, the parser keeps looking for the underscore in the interpolated variable

Minimal working example:

julia> using Markdown

julia> a_b = 3.0
3.0

julia> md"a_b = $(a_b)"
ERROR: syntax: invalid syntax (incomplete #<julia: Base.Meta.ParseError(msg="ParseError:\n# Error @ none:1:3\n(a\n# └ ── Expected `)`", detail=Base.JuliaSyntax.ParseError(source=Base.JuliaSyntax.SourceFile(code=Base.SubString{String}(string="(a", offset=0, ncodeunits=2), byte_offset=0, filename="none", first_line=1, line_starts=Array{Int64, 1}(dims=(2,), mem=Memory{Int64}(8, 0x74123b497da0)[1, 3, 0, 0, 0, 0, 0, 0])), diagnostics=Array{Base.JuliaSyntax.Diagnostic, 1}(dims=(1,), mem=Memory{Base.JuliaSyntax.Diagnostic}(8, 0x74123b48ca40)[Base.JuliaSyntax.Diagnostic(first_byte=3, last_byte=2, level=:error, message="Expected `)`"), Base.JuliaSyntax.Diagnostic(first_byte=0, last_byte=0, level=#<null>, message=#<null>), Base.JuliaSyntax.Diagnostic(first_byte=0, last_byte=0, level=#<null>, message=#<null>), Base.JuliaSyntax.Diagnostic(first_byte=0, last_byte=0, level=#<null>, message=#<null>), Base.JuliaSyntax.Diagnostic(first_byte=0, last_byte=0, level=#<null>, message=#<null>), Base.JuliaSyntax.Diagnostic(first_byte=0, last_byte=0, level=#<null>, message=#<null>), Base.JuliaSyntax.Diagnostic(first_byte=0, last_byte=0, level=#<null>, message=#<null>), Base.JuliaSyntax.Diagnostic(first_byte=0, last_byte=0, level=#<null>, message=#<null>)]), incomplete_tag=:other))>)
Stacktrace:
 [1] top-level scope
   @ REPL[3]:1

julia> md"a\_b = $(a_b)"
  a_b = 3.0

julia> md"a_b = $a_b"
ERROR: UndefVarError: `a` not defined in `Main`
Suggestion: check for spelling errors or missing imports.
Stacktrace:
 [1] top-level scope
   @ REPL[6]:1

julia> md"a\_b = $a_b"
  a_b = 3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions