CodeblockFilepathProcessor
in package
implements
MarkdownPreProcessorContract, MarkdownPostProcessorContract
Resolves file path comments found in Markdown code blocks into a neat badge shown in the top right corner.
Table of Contents
Interfaces
- MarkdownPreProcessorContract
- Process Markdown before it is converted to HTML.
- MarkdownPostProcessorContract
- Process Markdown after it is converted to HTML.
Properties
- $patterns : array<string|int, string>
- $torchlightKey : string
Methods
- postprocess() : string
- Process the meta-blocks added by the preprocessor, injecting the filepath badge template into the code block.
- preprocess() : string
- Extract lines matching the shortcode pattern and replace them with meta-blocks that will be processed later.
- injectLabelToCodeLine() : string
- injectLabelToTorchlightCodeLine() : string
- lineMatchesPattern() : bool
- resolveTemplate() : string
- trimHydeDirective() : string
Properties
$patterns
protected
static array<string|int, string>
$patterns
= ['// filepath: ', '// filepath ', '/* filepath: ', '/* filepath ', '# filepath: ', '# filepath ', '<!-- filepath: ', '<!-- filepath ']
$torchlightKey
protected
static string
$torchlightKey
= '<!-- Syntax highlighted by torchlight.dev -->'
Methods
postprocess()
Process the meta-blocks added by the preprocessor, injecting the filepath badge template into the code block.
public
static postprocess(string $html) : string
Parameters
- $html : string
-
HTML to be processed
Return values
string —$html Processed HTML output
preprocess()
Extract lines matching the shortcode pattern and replace them with meta-blocks that will be processed later.
public
static preprocess(string $markdown) : string
Parameters
- $markdown : string
-
Markdown to be processed
Return values
string —$markdown Processed Markdown output
injectLabelToCodeLine()
protected
static injectLabelToCodeLine(string $label, string $lines) : string
Parameters
- $label : string
- $lines : string
Return values
stringinjectLabelToTorchlightCodeLine()
protected
static injectLabelToTorchlightCodeLine(string $label, string $lines) : string
Parameters
- $label : string
- $lines : string
Return values
stringlineMatchesPattern()
protected
static lineMatchesPattern(string $line) : bool
Parameters
- $line : string
Return values
boolresolveTemplate()
protected
static resolveTemplate(string $path) : string
Parameters
- $path : string
Return values
stringtrimHydeDirective()
protected
static trimHydeDirective(string $line) : string
Parameters
- $line : string