Skip to content

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

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

Open
abhro opened this issue Feb 4, 2025 · 2 comments
Open

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

abhro opened this issue Feb 4, 2025 · 2 comments
Labels
markdown stdlib Julia's standard library

Comments

@abhro
Copy link
Contributor

abhro commented Feb 4, 2025

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
@abhro abhro changed the title @md_str parses underscores in interpolated variables @md_str parses underscores in interpolated variables (Markdown.jl) Feb 4, 2025
@nsajko nsajko added markdown stdlib Julia's standard library labels Feb 5, 2025
@KristofferC
Copy link
Member

Is this a duplicate of #57265?

@abhro
Copy link
Contributor Author

abhro commented Feb 5, 2025

I don't know if you were talking about this being a duplicate of a different issue, but I think the link pasted here #57265 (comment) is to the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
markdown stdlib Julia's standard library
Projects
None yet
Development

No branches or pull requests

3 participants