Bookstack: No syntax highlighting exists for PHP

Created on 28 Jul 2019  Â·  8Comments  Â·  Source: BookStackApp/BookStack

Describe the bug
You can select syntax highlighting for PHP in code blocks, but no highlighting is applied when no <?php is added to the top of the snippet.

Steps To Reproduce

  1. Draft a new page
  2. Click on Formats > Code Block
  3. Select PHP from the list
  4. Type some PHP without <?php
  5. Tada! No syntax highlighting

Expected behavior
Syntax highlighting should be applied to the code block like it would if Javascript or Python were to be selected, even without <?php

Screenshots
With JS
image
With PHP
image

Your Configuration (please complete the following information):

  • Exact BookStack Version: BookStack v0.26.3
  • PHP Version: PHP Version 7.2.19
  • Apache2 on a DigitalOcean VPS
Front-End Enhancement WYSIWYG Editor > Markdown Editor

Most helpful comment

Updated applied in master, For the next release (v0.28).

BookStack will now check for php opening tags (<?php) and change the exact mode depending on if they exist, meaning that standalone PHP code will now highlight as expected.

All 8 comments

Thanks for raising @codemicro.

Is a little awkward due to the nature of PHP & how it can be mixed in with other content (HTML, text, etc..). Looks like such a mode is possible:
https://github.com/codemirror/CodeMirror/issues/137

We'll have to ensure it won't effect existing mixed blocks of code with PHP chosen. Might have to be another option in the code block editor language list.

I'm using the Markdown editor myself (because it's a lot faster for me) and PHP does highlight just fine in the markdown itself but then when I look at the right side (where the "output" is shown), it's not there.

This does imply that there is some highlighter for it in place already?

@FinlayDaG33k Code blocks are not highlighted in the Markdown preview window for performance reasons. Highlighting should be active when viewing the live page after saving.

Updated applied in master, For the next release (v0.28).

BookStack will now check for php opening tags (<?php) and change the exact mode depending on if they exist, meaning that standalone PHP code will now highlight as expected.

Thank you very much! :)

@ssddanbrown Is there a way to highlight the PHP code inside code block but without using opening tags?

For example like here by marking code block as php one.

class Event extends Relations\HasMany
{
  ...
}

and that's preview from my result page

obraz

That is exactly the scenario I set out when I first opened this issue and,
as the comments clearly say, a fix has been implemented and will be
released in v0.28.

On Sat, 18 Jan 2020, 11:20 pm sabat24, notifications@github.com wrote:

@ssddanbrown https://github.com/ssddanbrown Is there a way to highlight
the PHP code inside code block but without using opening tags?

For example like here by marking code block as php one.

class Event extends Relations\HasMany{ ...}

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/BookStackApp/BookStack/issues/1557?email_source=notifications&email_token=AGA45ZO44RAGKPZLZS4UHZLQ6OFDPA5CNFSM4IHM6MN2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEJKEFAY#issuecomment-575947395,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AGA45ZO6YL7LSALURXJM3TDQ6OFDPANCNFSM4IHM6MNQ
.

Ok. I misunderstood the answer. I thought that that line "BookStack will now check for php opening tags ( Now it's clear. Thanks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Nedimko123 picture Nedimko123  Â·  3Comments

stuartajd picture stuartajd  Â·  4Comments

ensemblebd picture ensemblebd  Â·  3Comments

tpetrauskas picture tpetrauskas  Â·  4Comments

Zeigren picture Zeigren  Â·  3Comments