mirror of
https://github.com/silverstripe/silverstripe-docsviewer
synced 2024-10-22 09:05:56 +00:00
BUGFIX Fixed <code> formatting for api links
This commit is contained in:
parent
b96b2b4016
commit
b8cdec0531
@ -46,6 +46,14 @@ class DocumentationParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Rewrite links with special "api:" prefix, from two possible formats:
|
||||||
|
* 1. [api:DataObject]
|
||||||
|
* 2. (My Title)(api:DataObject)
|
||||||
|
*
|
||||||
|
* Hack: Replaces any backticks with "<code>" blocks,
|
||||||
|
* as the currently used markdown parser doesn't resolve links in backticks,
|
||||||
|
* but does resolve in "<code>" blocks.
|
||||||
|
*
|
||||||
* @param String $md
|
* @param String $md
|
||||||
* @param DocumentationPage $page
|
* @param DocumentationPage $page
|
||||||
* @return String
|
* @return String
|
||||||
@ -53,12 +61,14 @@ class DocumentationParser {
|
|||||||
static function rewrite_api_links($md, $page) {
|
static function rewrite_api_links($md, $page) {
|
||||||
// Links with titles
|
// Links with titles
|
||||||
$re = '/
|
$re = '/
|
||||||
|
`?
|
||||||
\[
|
\[
|
||||||
(.*?) # link title (non greedy)
|
(.*?) # link title (non greedy)
|
||||||
\]
|
\]
|
||||||
\(
|
\(
|
||||||
api:(.*?) # link url (non greedy)
|
api:(.*?) # link url (non greedy)
|
||||||
\)
|
\)
|
||||||
|
`?
|
||||||
/x';
|
/x';
|
||||||
preg_match_all($re, $md, $linksWithTitles);
|
preg_match_all($re, $md, $linksWithTitles);
|
||||||
if($linksWithTitles) foreach($linksWithTitles[0] as $i => $match) {
|
if($linksWithTitles) foreach($linksWithTitles[0] as $i => $match) {
|
||||||
@ -67,16 +77,18 @@ class DocumentationParser {
|
|||||||
$url = sprintf(self::$api_link_base, $subject, $page->getVersion(), $page->getEntity()->getModuleFolder());
|
$url = sprintf(self::$api_link_base, $subject, $page->getVersion(), $page->getEntity()->getModuleFolder());
|
||||||
$md = str_replace(
|
$md = str_replace(
|
||||||
$match,
|
$match,
|
||||||
sprintf('[%s](%s)', $title, $url),
|
sprintf('<code>[%s](%s)</code>', $title, $url),
|
||||||
$md
|
$md
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bare links
|
// Bare links
|
||||||
$re = '/
|
$re = '/
|
||||||
|
`?
|
||||||
\[
|
\[
|
||||||
api:(.*?)
|
api:(.*?)
|
||||||
\]
|
\]
|
||||||
|
`?
|
||||||
/x';
|
/x';
|
||||||
preg_match_all($re, $md, $links);
|
preg_match_all($re, $md, $links);
|
||||||
if($links) foreach($links[0] as $i => $match) {
|
if($links) foreach($links[0] as $i => $match) {
|
||||||
@ -84,7 +96,7 @@ class DocumentationParser {
|
|||||||
$url = sprintf(self::$api_link_base, $subject, $page->getVersion(), $page->getEntity()->getModuleFolder());
|
$url = sprintf(self::$api_link_base, $subject, $page->getVersion(), $page->getEntity()->getModuleFolder());
|
||||||
$md = str_replace(
|
$md = str_replace(
|
||||||
$match,
|
$match,
|
||||||
sprintf('[%s](%s)', $subject, $url),
|
sprintf('<code>[%s](%s)</code>', $subject, $url),
|
||||||
$md
|
$md
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user