Download
We're evolving to serve you better! This current forum has transitioned to read-only mode. For new discussions, support, and engagement, we've moved to GitHub Discussions.

Issue with Prism.js code highlighting, Line Breaks, Copy Code (WYSIWYG Editor)

  • #7007
    Avatar photo[anonymous]

    I just spent the last hour trying to get the Prism Code highlight to work on the Mercury theme, and was stuck on the code displaying as one long line with a horizontal scroll, as opposed to including the line breaks from the copied code. I had no issues with the Block Editor, but the WYSIWYG Editor had the horizontal scroll issue.

    I then tried the following steps:

    1. Paste your code as is in the editor
    2. Highlight the code and select “Pre” from the 2nd dropdown on the 2nd row of the Post Editor.
    3. With the code still highlighted, select “Line numbers < pre >” from the 1st dropdown on the 2nd row of the Post Editor.
    4. With the code still highlighted, select “Code” from the 2nd dropdown on the 2nd row of the Post Editor.
    5. With the code still highlighted, select “Code-[LANGUAGE]” from the 1st dropdown on the 2nd row of the Post Editor.

    This helped with eliminating the horizontal scroll, but clicking on “Copy” only copied the first line of code…

    It appears that when a code reference is added to the WYSIWYG Editor, it creates separate < code > elements for each line inside the < pre >, and when you try to place all the code in the same < code > element, the line breaks aren’t generated properly (even if you manually add < br > elements).

    Doc reference: https://getpublii.com/docs/highlight-your-code-syntax-with-prism-js.html

    #7012
    Avatar photoBob

    Closed due to duplicate Github post → https://github.com/GetPublii/Publii/issues/1084