Skip to content
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

How to display incomplete PHP code outside of a code block #1213

Closed
4 tasks done
charliematters opened this issue Aug 16, 2023 · 4 comments
Closed
4 tasks done

How to display incomplete PHP code outside of a code block #1213

charliematters opened this issue Aug 16, 2023 · 4 comments
Labels
🙋 no/question This does not need any changes 👎 phase/no Post cannot or will not be acted on

Comments

@charliematters
Copy link

Initial checklist

Affected packages and versions

Remark@10, Rehype@9

Link to runnable example

https://stackblitz.com/edit/github-uzm7cu?file=src%2Fmain.ts

Steps to reproduce

We have some users unfamiliar with markdown who are adding snippets of code in without code blocks. In one case, they are adding an incomplete php section:

Before
<?php
// PHP code
After

And reporting that it is not working as expected:

Before

I realise this is an education issue, however the first google result for a markdown editor (StackEdit) handles this case in a more expected way, outputting this:

Before

<?php // PHP code After

Expected behavior

The valid markdown after the PHP tag should still be shown, along with the incomplete PHP

Actual behavior

The PHP start tag stops any further output

Runtime

Node v17

Package manager

npm 8

OS

Windows

Build and bundle tools

Webpack

@github-actions github-actions bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels Aug 16, 2023
@ChristianMurphy
Copy link
Member

ChristianMurphy commented Aug 16, 2023

Welcome @charliematters! 👋

TL;DR
There is no bug, what you describe is how CommonMark works, the best approach would be to educate content authors on how standard markdown works.

Long version
<?php triggers the start of an HTML block, and everything inside is interpreted as HTML attributes. (CommonMark reference implementation https://spec.commonmark.org/dingus/?text=Before%0A%3C%3Fphp%0A%2F%2F%20PHP%20code%0AAfter)

If authors aim is to show what PHP syntax looks like, they should use a code block

Before
```php
<?php
// PHP code
```
After

If the intent is to show the PHP content as plain text, escape it

Before
\<?php
// PHP code
After

Or if the intent is to use the PHP as a pre-processor for markdown, run it through the pre-processor first.


Reading between the lines of your issue a bit, it sounds like content author may have an interest in adding interactive content or database backed content to the page?
If so consider leveraging https://github.com/mdx-js/mdx/ or https://github.com/remarkjs/remark-directive

@ChristianMurphy ChristianMurphy closed this as not planned Won't fix, can't repro, duplicate, stale Aug 16, 2023
@ChristianMurphy ChristianMurphy added the 🙋 no/question This does not need any changes label Aug 16, 2023
@github-actions

This comment has been minimized.

@github-actions github-actions bot added 👎 phase/no Post cannot or will not be acted on and removed 🤞 phase/open Post is being triaged manually labels Aug 16, 2023
@wooorm
Copy link
Member

wooorm commented Aug 16, 2023

Also: we support plugins. If you write a plugin, you can turn html into text, making it visible.

react-markdown at least has an option for it.

Perhaps you can share your actual setup so that we can practically help you.

@charliematters
Copy link
Author

Thanks for the offer, and your answers have been really helpful.

I hate to be that person, but it's a proprietary codebase so can't share it.

We do actually have a bunch of plugins in our pipeline (some of which are hand-made), so I'm going to report back to the user that that's how (our) markdown works and add a low-priority ticket to work on a plugin which grabs those text nodes and renders them in a basic way

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🙋 no/question This does not need any changes 👎 phase/no Post cannot or will not be acted on
Development

No branches or pull requests

3 participants