waldyrious / rst-playground

Browser-based reStructuredText playground, built on Pyodide and docutils.
https://waldyrious.github.io/rst-playground
ISC License
1 stars 4 forks source link

Implement multiline input #6

Closed not-my-profile closed 1 year ago

not-my-profile commented 1 year ago

Fixes #4, fixes #7 (moved to #12), fixes #8 (moved to #10) and other stuff (moved to #9 and #13).

waldyrious commented 1 year ago

Thanks so much for tackling these! Would you mind moving 713ef32642db1386dcd7cdce551020d3338653ae to a separate PR? I'd like to discuss those changes separately. And maybe also split out the moving of the CSS and JS code to separate files, so that this PR's global diff is more readable.

I can do both if you'd prefer.

waldyrious commented 1 year ago

Also, 5c1055b7b814215e3b2329152fdca8d0d593ddfe is already included in #1. Let me merge that one first since these changes are more substantial (though fortunately they don't overlap much).

not-my-profile commented 1 year ago

I am not gonna open several PRs for this ... GitHub does let you view the diffs of the individual commits ...

And I think the changes in 713ef32642db1386dcd7cdce551020d3338653ae can also be discussed post merge ... but I don't mind it if you want to split up this PR ... I just don't see the point.

waldyrious commented 1 year ago

No worries, it's just my OCD :sweat_smile: Also, GitHub's per-commit view is a little cumbersome to use. I'll split the PR.

waldyrious commented 1 year ago

Update: I've split the other changes into #9 and #10, and rebased this PR (dropping 5c1055b7b in favor of the changes in #1). Sorry for the inconvenience :)

I still would like to split this further, but I'm out of time for the moment, and will pick this up later.

waldyrious commented 1 year ago

(Adding the expanded commit message with the explanation here, for convenience)

The previous approach of interpolating the contents of the textarea directly into the JavaScript template literal containing Python code didn't work because:

  1. The string contained newlines, so it had to be specified using triple quotes (""").
  2. The template literal is indented within the JavaScript code, and the whitespace characters used for indentation are part of the string; i.e. the whole Python script is indented; however, when the textarea contents got interpolated into it, the resulting Python code would contain negative indentation, something like this:
       from docutils.core import publish_string
       publish_string("""foo
    bar""", writer_name='html5').decode("utf-8")

    ...so Python would complain about invalid syntax.

Passing the string via a variable (rather than injecting it directly into the Python code) avoids this issue because the Python code doesn't change shape depending on the input text.

In any case, it's unadvisable to directly interpolate user input into code, because it can lead to code injection, so the new approach is also safer.

waldyrious commented 1 year ago

WDYT of the PR as it stands, @not-my-profile?