JuliaPluto / PlutoUI.jl

https://featured.plutojl.org/basic/plutoui.jl
The Unlicense
299 stars 54 forks source link

Error in markdown with interpolated @bind #286

Closed sairus7 closed 4 months ago

sairus7 commented 5 months ago

If a variable name has underscore and I mention it in markdown together with bind interpolation, the following error occurs:

md"""
ch_num: $(@bind ch_num Select(1:8, default = 1))
"""
syntax: invalid syntax (incomplete #<julia: Base.Meta.ParseError(msg="ParseError:

# Error @ none:1:10

(@bind ch

# └ ── Expected `)`", detail=Base.JuliaSyntax.ParseError(source=Base.JuliaSyntax.SourceFile(code=Base.SubString{String}(string="(@bind ch", offset=0, ncodeunits=9), byte_offset=0, filename="none", first_line=1, line_starts=Array{Int64, (2,)}[1, 10]), diagnostics=Array{Base.JuliaSyntax.Diagnostic, (1,)}[Base.JuliaSyntax.Diagnostic(first_byte=10, last_byte=9, level=:error, message="Expected `)`")], incomplete_tag=:other))>)

top-level scope@none:1
top-level scope@none:1
pankgeorg commented 5 months ago

Could this be a JuliaSyntax issue? @c42f does this ring any bell? 🙏🏽

fonsp commented 4 months ago

The _str macros don't support interpolation, and md_str contains its own implementation of interpolation that does not always work.

In this case, I think the issue is that @md_str tries to find the subexpression that is being interpolated (should be @bind ch_num Select(1:8, default = 1)), but this gives a wrong result. My guess is that it finds (@bind ch_num Select(1:8, default = 1), this gives the same error:

image

You can tell that this is not an issue with the parser, because changing md to html or raw fixes it:

image

So the solution is: switch to MarkdownLiteral.jl, or make it simpler for Markdown:

let
    bond = @bind ch_num Select(1:8, default = 1)
    md"""
    ch_num: $(bond)
    """
end