Skip to content

Commit

Permalink
BlockQuoteModule, PhraseModule: removed support for 'cite' (BC break)
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Nov 21, 2023
1 parent 7a5fd9c commit 6d8365c
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 61 deletions.
1 change: 0 additions & 1 deletion src/Texy/Modifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ final class Modifier
public ?string $hAlign = null;
public ?string $vAlign = null;
public ?string $title = null;
public ?string $cite = null;

/** @var array<string, int> list of properties which are regarded as HTML element attributes */
public static array $elAttrs = [
Expand Down
41 changes: 3 additions & 38 deletions src/Texy/Modules/BlockQuoteModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,10 @@ public function pattern(Texy\BlockParser $parser, array $matches): Texy\HtmlElem
$content = '';
$spaces = '';
do {
if ($mPrefix === ':') {
$mod->cite = $texy->blockQuoteModule->citeLink($mContent);
$content .= "\n";
} else {
if ($spaces === '') {
$spaces = max(1, strlen($mPrefix));
}

$content .= $mContent . "\n";
if ($spaces === '') {
$spaces = max(1, strlen($mPrefix));
}
$content .= $mContent . "\n";

if (!$parser->next("#^>(?:|([\\ \\t]{1,$spaces}|:)(.*))()$#mA", $matches)) {
break;
Expand All @@ -72,7 +66,6 @@ public function pattern(Texy\BlockParser $parser, array $matches): Texy\HtmlElem
[, $mPrefix, $mContent] = $matches;
} while (true);

$el->attrs['cite'] = $mod->cite;
$el->parseBlock($texy, $content, $parser->isIndented());

// no content?
Expand All @@ -85,32 +78,4 @@ public function pattern(Texy\BlockParser $parser, array $matches): Texy\HtmlElem

return $el;
}


/**
* Converts cite source to URL.
*/
public function citeLink(string $link): ?string
{
$texy = $this->texy;

if ($link == null) {
return null;
}

if ($link[0] === '[') { // [ref]
$link = substr($link, 1, -1);
$ref = $texy->linkModule->getReference($link);
if ($ref) {
return Texy\Helpers::prependRoot($ref->URL, $texy->linkModule->root);
}
}

// special supported case
if (strncasecmp($link, 'www.', 4) === 0) {
return 'http://' . $link;
}

return Texy\Helpers::prependRoot($link, $texy->linkModule->root);
}
}
16 changes: 0 additions & 16 deletions src/Texy/Modules/PhraseModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ final class PhraseModule extends Texy\Module
'phrase/sub-alt' => 'sub',
'phrase/span' => 'a',
'phrase/span-alt' => 'a',
'phrase/cite' => 'cite',
'phrase/acronym' => 'abbr',
'phrase/acronym-alt' => 'abbr',
'phrase/code' => 'code',
Expand Down Expand Up @@ -150,13 +149,6 @@ public function __construct(Texy\Texy $texy)
'phrase/span-alt',
);

// ~~cite~~
$texy->registerLinePattern(
$this->patternPhrase(...),
'#(?<!\~)\~\~(?![\s~])((?:[^\r\n ~]++|[ ~])+)' . Patterns::MODIFIER . '?(?<![\s~])\~\~(?!\~)(?::(' . Patterns::LINK_URL . '))??()#Uu',
'phrase/cite',
);

// >>quote<<
$texy->registerLinePattern(
$this->patternPhrase(...),
Expand Down Expand Up @@ -225,7 +217,6 @@ public function __construct(Texy\Texy $texy)
$texy->allowed['phrase/del'] = false;
$texy->allowed['phrase/sup'] = false;
$texy->allowed['phrase/sub'] = false;
$texy->allowed['phrase/cite'] = false;
}


Expand Down Expand Up @@ -262,9 +253,6 @@ public function patternPhrase(LineParser $parser, array $matches, string $phrase
} elseif ($phrase === 'phrase/acronym' || $phrase === 'phrase/acronym-alt') {
$mod->title = trim(Texy\Helpers::unescapeHtml($mLink));

} elseif ($phrase === 'phrase/quote') {
$mod->cite = $texy->blockQuoteModule->citeLink($mLink);

} elseif ($mLink != null) {
$link = $texy->linkModule->factoryLink($mLink, null, $mContent);
}
Expand Down Expand Up @@ -323,10 +311,6 @@ private function solve(
} elseif ($tag) {
$el = new Texy\HtmlElement($tag, $content);
$mod->decorate($texy, $el);

if ($tag === 'q') {
$el->attrs['cite'] = $mod->cite;
}
} else {
$el = $content; // trick
}
Expand Down
9 changes: 5 additions & 4 deletions tests/Texy/expected/syntax.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,13 @@ <h2>This is a header.</h2>

<h2>BlockQuote</h2>

<blockquote cite="http://www.microsoft.com">
<blockquote>
<p>This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus. Vestibulum
enim wisi, viverra nec, fringilla in, laoreet vitae, risus.</p>

<p>640 K should be enough for everyone</p>
<p>640 K should be enough for everyone <a
href="http://www.microsoft.com">http://www.microsoft.com</a></p>
</blockquote>

<h3>nested</h3>
Expand Down Expand Up @@ -143,9 +144,9 @@ <h2>Phrases</h2>
<p>Formatting: <em>emphasis</em>, <strong>strong emphasis</strong> and <strong
style="color:green"><em>stronger emphasis</em></strong></p>

<p>Quotes: <q cite="http://www.lipsum.com">Lorem Ipsum Dolores</q></p>
<p>Quotes: <a href="http://www.lipsum.com"><q>Lorem Ipsum Dolores</q></a></p>

<p>Cite: As <cite>Frank Borland</cite> said, …</p>
<p>Cite: As ~~Frank Borland~~ said, …</p>

<p>And other: <sup>superscript</sup> vs. <sub>subscript</sub></p>

Expand Down
4 changes: 2 additions & 2 deletions tests/Texy/expected/syntax.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ BlockQuote
consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus. Vestibulum
enim wisi, viverra nec, fringilla in, laoreet vitae, risus.

640 K should be enough for everyone
640 K should be enough for everyone http://www.microsoft.com


nested
Expand Down Expand Up @@ -134,7 +134,7 @@ Formatting: emphasis, strong emphasis and stronger emphasis

Quotes: Lorem Ipsum Dolores

Cite: As Frank Borland said, …
Cite: As ~~Frank Borland~~ said, …

And other: superscript vs. subscript

Expand Down

0 comments on commit 6d8365c

Please sign in to comment.