Displaying Code in book

Hello,
This might have been asked and answered in the forum, but I couldn’t find any posts, so I’m going to ask here. I want to show code samples, like HTML and Javascript in my book. But, when I just use. < code > I’m losing the indentations and spaces, when I try to use < pre > it keeps my spacing and indents on the javascript, but renders the html tags in there. Trying to nest the two tags doesn’t seem to work either. So, can someone tell me if there is another way, even if there is a plugin that will work with Pressbooks, like I would love to have something that actually color coded and line numbered the code, but I’ll take just not rendered and structured.
Any help would be appreciated!
Thanks,
Robbie

Hi @ostraining – you may want to try <pre><code> ... </code></pre> – i.e. wrapping your code block inside of a pre formatted element. If you want syntax highlighting, at present you’ll probably have to rely on a WordPress plugin, though you’ll need to note that highlighting won’t be applied to any export formats you produce, as most plugins will apply highlighting via JavaScript, which won’t work on export. We have an issue in our backlog to add this feature, but haven’t begun work on it yet: https://github.com/pressbooks/ideas/issues/88

Thanks @SteelWagstaff - We had been doing that double up but it was tricky to do with the visual editor without wiping out one or the other, and if you try just the text editor < code > doesn’t work it’s magic on the <'s… But, I think my designer has figured out a method between the visual and text editor now that seems to be working to convert the <'s and retain the spaces. We have our code in Shaded Boxes, so we select shaded box in Visual, then switch to Text and manually add < pre > and leaving the cursor in between them, switch to the Visual again and click the Code button and paste. That scenario seems to be working thus far… crossing our fingers it doesn’t mess up somewhere along the way, lol.
Thank you again for taking the time to answer my post, it is appreciated!
Cheers!

My pleasure. Sorry that the workaround sounds so painful, but glad you’ve got a workflow that seems to be working for now. Would love to hear more about your needs/interests in terms of syntax highlighting as well. Feel free to drop a comment on the GitHub ticket shared previously or leave a note here – we’ll be more likely to build a solution that takes your needs into account if we know what they are!