Skip to content

Commit

Permalink
add support for Comment Syntax support
Browse files Browse the repository at this point in the history
  • Loading branch information
nomadjimbob committed May 31, 2023
1 parent 4b75a53 commit d0d6c45
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 49 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
- Sidebars now collapse by default on mobile. This can be overridden with the `sidebarMobileDefaultCollapse` option
- The mikio LESS stylesheet is now disabled by default, with a precompilied CSS used. This can be reverted using the `useLESS` option

## Incompadibilities

**Comment Syntax support** converts custom control macros such as the Mikio macro `~~hero-image ...~~` into comments. If you plan to use this extension on your site, you will need to use the alternative macro format of `-~hero-image ...~-` for Mikio to detect the information.

## Configuration

The configuration can be change with the [Configuration Manager Plugin](https://www.dokuwiki.org/plugin:config)
Expand Down Expand Up @@ -233,6 +237,10 @@ If the plugin is installed, the **Template Styles Settings** page will be expand

## Releases

- **_NEXT_**

- Mikio Control Macros now support the format `-~SETTING~-` as well as the standard `~~SETTING~~`. This fixes an incompatibility with the [Comment Syntax support](https://www.dokuwiki.org/plugin:commentsyntax) extension.

- **_2023-05-19_**

- Fixed notifications appearing in weird places at times.
Expand Down
75 changes: 26 additions & 49 deletions mikio.php
Original file line number Diff line number Diff line change
Expand Up @@ -1861,27 +1861,19 @@ public function parseContent(string $content)

/* Hero subtitle */
foreach ($html->find('p') as $elm) {
$i = stripos($elm->innertext, '~~hero-subtitle');
if ($i !== false) {
$j = strpos($elm->innertext, '~~', ($i + 2));
if ($j !== false) {
if ($j > ($i + 16)) {
$subtitle = substr($elm->innertext, ($i + 16), ($j - $i - 16));
$this->footerScript['hero-subtitle'] = 'mikio.setHeroSubTitle(\'' . $subtitle . '\')';

// $elm->innertext = substr($elm->innertext, 0, $i + 2) . substr($elm->innertext, $j + 2);
$elm->innertext = preg_replace('/~~hero-subtitle (.+?)~~.*/ui', '', $elm->innertext);
}
if (preg_match('/[~-]~hero-subtitle (.+?)~[~-]/ui', $elm->innertext, $matches) === 1) {
$subtitle = $matches[1];
$this->footerScript['hero-subtitle'] = 'mikio.setHeroSubTitle(\'' . $subtitle . '\')';

break;
}
$elm->innertext = preg_replace('/[~-]~hero-subtitle (.+?)~[~-]/ui', '', $elm->innertext);
break;
}
}

/* Hero image */
foreach ($html->find('p') as $elm) {
$image = '';
preg_match('/~~hero-image (.+?)~~(?!.?")/ui', $elm->innertext, $matches);
preg_match('/[~-]~hero-image (.+?)~[~-](?!.?")/ui', $elm->innertext, $matches);
if (count($matches) > 0) {
preg_match('/<img.*src="(.+?)"/ui', $matches[1], $imageTagMatches);
if (count($imageTagMatches) > 0) {
Expand All @@ -1906,56 +1898,41 @@ public function parseContent(string $content)

$this->footerScript['hero-image'] = 'mikio.setHeroImage(\'' . $image . '\')';

$elm->innertext = preg_replace('/~~hero-image (.+?)~~.*/ui', '', $elm->innertext);
$elm->innertext = preg_replace('/[~-]~hero-image (.+?)~[~-].*/ui', '', $elm->innertext);
}//end if
}//end foreach

/* Hero colors - ~~hero-colors [background-color] [hero-title-color] [hero-subtitle-color]
[breadcrumb-text-color] [breadcrumb-hover-color] (use 'initial' for original color) */
foreach ($html->find('p') as $elm) {
$i = stripos($elm->innertext, '~~hero-colors');
if ($i !== false) {
$j = strpos($elm->innertext, '~~', ($i + 2));
if ($j !== false) {
if ($j > ($i + 14)) {
$color = substr($elm->innertext, ($i + 14), ($j - $i - 14));
$this->footerScript['hero-colors'] = 'mikio.setHeroColor(\'' . $color . '\')';

$elm->innertext = preg_replace('/~~hero-colors (.+?)~~.*/ui', '', $elm->innertext);
}
if (preg_match('/[~-]~hero-colors (.+?)~[~-]/ui', $elm->innertext, $matches) === 1) {
$subtitle = $matches[1];
$this->footerScript['hero-colors'] = 'mikio.setHeroColor(\'' . $subtitle . '\')';

break;
}
$elm->innertext = preg_replace('/[~-]~hero-colors (.+?)~[~-]/ui', '', $elm->innertext);
break;
}
}

/* Hide parts - ~~hide-parts [parts]~~ */
foreach ($html->find('p') as $elm) {
$i = stripos($elm->innertext, '~~hide-parts');
if ($i !== false) {
$j = strpos($elm->innertext, '~~', ($i + 2));
if ($j !== false) {
if ($j > ($i + 13)) {
$parts = explode(' ', substr($elm->innertext, ($i + 13), ($j - $i - 13)));
$script = '';

foreach ($parts as $part) {
// $part = trim($part);
if (strlen($part) > 0) {
$script .= 'mikio.hidePart(\'' . $part . '\');';
}
}
if (preg_match('/[~-]~hero-colors (.+?)~[~-]/ui', $elm->innertext, $matches) === 1) {
$parts = explode(' ', $matches[1]);
$script = '';

if (strlen($script) > 0) {
$this->footerScript['hide-parts'] = $script;
}

$elm->innertext = preg_replace('/~~hide-parts (.+?)~~.*/ui', '', $elm->innertext);
foreach ($parts as $part) {
if (strlen($part) > 0) {
$script .= 'mikio.hidePart(\'' . $part . '\');';
}
}

break;
}//end if
}//end if
if (strlen($script) > 0) {
$this->footerScript['hide-parts'] = $script;
}

$elm->innertext = preg_replace('/[~-]~hero-parts (.+?)~[~-]/ui', '', $elm->innertext);
break;
}
}//end foreach


Expand Down

0 comments on commit d0d6c45

Please sign in to comment.