我为使用 Laravel Blade 引擎的 Web 平台编写文档,以允许用户制作和共享脚本。代码片段通常是有用的或必要的,显然语法突出显示使它们更易于阅读。
问题是我要离开 Github,而且很少有其他地方似乎支持 Blade 突出显示,所以我想知道是否有其他更流行的语言具有类似的语法,我可以将其定位为具有体面的突出显示,甚至如果它不完美。
我选择了 Gitbook,它使用 Prism 来突出显示,所以任何东西都是公平的。对于那些不熟悉 Blade 的人来说,这是一个示例代码块:
@foreach($_abilities as $ability)
{{-- Set up a more convenient array name --}}
@if($ability = $_abilities[$loop->index]) @endif
{{-- Ability name (and type) --}}
<h4>{{ $ability["name"] }} @isset($ability["type"]) ({{ $ability["type"] }}) @endisset</h4>
{{-- Link to Ability; use {!! !!} to parse HTML --}}
{!! $ability["link"] !!}
{{-- Parent Ability --}}
@isset($ability["parent"]) has a parent Ability named <b>{{ $ability["parent"]["name"] }}</b>.
@else has no parent Ability.
@endisset
{{-- Ability tags --}}
@if($ability["tags"]) It has the following tags: <i>
{{-- This array only has names, not key-value pairs, so we only need "as $tag" --}}
@foreach($ability["tags"] as $tag)
{{-- We’ll add a period at the end, or a comma in between tags --}}
@if($loop->last){{ $tag }}.
@else{{ $tag }},
@endif
@endforeach </i><br>
@else It has no tags.<br>
@endif
{{-- Ability charges --}}
Charges:
{{-- Used charges can be null, but we want them to default to 0 if max charges are set, so we use "?: 0" --}}
@isset($ability["charges"]) {{ $ability["used_charges"] ?: 0 }} used out of {{ $ability["charges"] }}.<br>
@else N/A.<br>
@endisset
{{-- Ability entry and image; use {!! !!} to parse HTML --}}
Description:<br>
{!! $ability["entry"] !!}<br>
{!! $ability["thumb"] !!}
@endforeach
基本上是 PHP、HTML 等的混杂。
我最终选择了Parser,原因如下:
SPARQL 是一个很好的竞争者,但在 HTML 方面表现不佳,并且突出显示了保留字,包括 @if 指令中的“if”。
有一些是可以接受的,但与那两个还差得很远。列出它们,以防其他人正在寻找不支持 Parser 和 SPARQL 的其他选项:Concurnas、Crystal、Perl。