mirror of
https://tildegit.org/sbgodin/HtmGem.git
synced 2023-08-25 13:53:12 +02:00
wip
This commit is contained in:
parent
4de4f45b84
commit
bf7a2ec379
2
TODO
2
TODO
@ -3,6 +3,7 @@
|
||||
* manage 404: Display better errors.
|
||||
* alt texts on pre and quote?
|
||||
* a way to get the source of a page, using urlrewriting
|
||||
* options to activate the text decoration
|
||||
* HTML caching: Nginx tries the html, if not found use this script to build it
|
||||
* any error on one read line logs and goes to the next line, resetting modes
|
||||
* configuration: Fetch configuration in current dir, tries parents.
|
||||
@ -19,3 +20,4 @@
|
||||
* Be able to navigate (custom the links) when using htmgen.php?url=…
|
||||
* Text localisation
|
||||
* Search all cases where a narrow no-break space would apply
|
||||
* Manage logging (cache refresh, debug)
|
||||
|
63
htmgem.php
63
htmgem.php
@ -73,8 +73,9 @@ $mode = null;
|
||||
$mode_textAttributes = true;
|
||||
foreach ($fileLines as $line) {
|
||||
$reDoCount = 0;
|
||||
$mode_textAttributes_temp = false;
|
||||
while (true) {
|
||||
if ($reDoCount>1) die("Too many loops");
|
||||
if ($reDoCount>2) die("Too many loops: ".$mode);
|
||||
$reDoCount += 1;
|
||||
$line1 = substr($line, 0, 1); // $line can be modified
|
||||
$line2 = substr($line, 0, 2); // in the meantime.
|
||||
@ -82,6 +83,16 @@ foreach ($fileLines as $line) {
|
||||
if (is_null($mode)) {
|
||||
if (empty($line)) {
|
||||
echo "<p> </p>\n";
|
||||
} elseif ('^^^' == $line3) {
|
||||
$mode_textAttributes = !$mode_textAttributes;
|
||||
} elseif ('^' == $line1) {
|
||||
if (preg_match("/^\^\s*(.*)$/", $line, $parts)) {
|
||||
$line = $parts[1];
|
||||
$mode_textAttributes_temp = true;
|
||||
} else {
|
||||
$mode = "raw";
|
||||
}
|
||||
continue;
|
||||
} elseif ("#" == $line1) {
|
||||
preg_match("/^(#{1,3})\s*(.*)/", $line, $sharps);
|
||||
$h_level = strlen($sharps[1]);
|
||||
@ -93,7 +104,7 @@ foreach ($fileLines as $line) {
|
||||
case 3: echo "<h3>".$text."</h3>\n"; break;
|
||||
}
|
||||
} elseif ("=>" == $line2) {
|
||||
preg_match("/^=>\s*([^\s]+)(\s+(.*))?$/", $line, $linkParts);
|
||||
if (preg_match("/^=>\s*([^\s]+)(?:\s+(.*))?$/", $line, $linkParts)) {
|
||||
$url_link = $linkParts[1];
|
||||
$url_label = @$linkParts[2];
|
||||
if (empty(trim($url_label))) {
|
||||
@ -103,8 +114,10 @@ foreach ($fileLines as $line) {
|
||||
htmlPrepare($url_label);
|
||||
}
|
||||
echo "<p><a href='".$url_link."'>".$url_label."</a></p>\n";
|
||||
} elseif ('"""' == $line3) {
|
||||
$mode_textAttributes = !$mode_textAttributes;
|
||||
} else {
|
||||
$mode = "raw";
|
||||
continue;
|
||||
}
|
||||
} elseif ("```" == $line3) {
|
||||
$mode="pre";
|
||||
echo "<pre>\n";
|
||||
@ -117,21 +130,27 @@ foreach ($fileLines as $line) {
|
||||
echo "<p> </p>\n";
|
||||
else
|
||||
htmlPrepare($quote);
|
||||
if ($mode_textAttributes) addTextAttributes($line);
|
||||
if ($mode_textAttributes xor $mode_textAttributes_temp) addTextAttributes($line);
|
||||
echo "<p>".$quote."</p>\n";
|
||||
} elseif ("*" == $line1 && "**" != $line2) {
|
||||
$mode = "ul";
|
||||
} elseif ("* " == $line2) {
|
||||
echo "<ul>\n";
|
||||
$mode = "ul";
|
||||
continue;
|
||||
} else {
|
||||
htmlPrepare($line);
|
||||
if ($mode_textAttributes) addTextAttributes($line);
|
||||
echo "<p>$line</p>\n";
|
||||
$mode = "raw";
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if ("raw"==$mode) {
|
||||
htmlPrepare($line);
|
||||
if ($mode_textAttributes xor $mode_textAttributes_temp) addTextAttributes($line);
|
||||
if (empty($line)) $line = " ";
|
||||
echo "<p>$line</p>\n";
|
||||
$mode = null;
|
||||
} elseif ("pre"==$mode) {
|
||||
if ("```" == $line3) {
|
||||
$mode=null;
|
||||
echo "</pre>\n";
|
||||
$mode = null;
|
||||
} else {
|
||||
htmlPrepare($line);
|
||||
echo $line."\n";
|
||||
@ -146,27 +165,31 @@ foreach ($fileLines as $line) {
|
||||
htmlPrepare($quote);
|
||||
echo "<p>".$quote."</p>\n";
|
||||
} else {
|
||||
$mode=null;
|
||||
echo "</blockquote>\n";
|
||||
$mode = null;
|
||||
continue;
|
||||
}
|
||||
} elseif ("ul"==$mode) {
|
||||
if ("*" == $line1 && "**" != $line2) {
|
||||
if ("* " == $line2) {
|
||||
preg_match("/^\*\s*(.*)$/", $line, $ulParts);
|
||||
$li = $ulParts[1];
|
||||
if (empty($li))
|
||||
if (empty($li)) {
|
||||
echo "<li> \n";
|
||||
else
|
||||
htmlPrepare($li);
|
||||
addTextAttributes($li);
|
||||
echo "<li>".$li."\n";
|
||||
} else {
|
||||
$mode = null;
|
||||
htmlPrepare($li);
|
||||
if ($mode_textAttributes xor $mode_textAttributes_temp) addTextAttributes($line);
|
||||
echo "<li>".$li."\n";
|
||||
}
|
||||
} else {
|
||||
echo "</ul>\n";
|
||||
$mode = null;
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
die("Unexpected mode: $mode!");
|
||||
}
|
||||
break;
|
||||
}
|
||||
break; // exits the while(true) as no continue occured
|
||||
}
|
||||
}
|
||||
$body = ob_get_contents();
|
||||
|
128
tests/test.gmi
128
tests/test.gmi
@ -1,19 +1,117 @@
|
||||
# Test page
|
||||
|
||||
* puce
|
||||
=> lien1
|
||||
=> lien2
|
||||
|
||||
```
|
||||
The text as it is in the source code, in a preformatted block.
|
||||
```
|
||||
The text as it is rendered, of course the following examples will have identical preformatted content and rendered content.
|
||||
|
||||
```
|
||||
* single line
|
||||
```
|
||||
* single line
|
||||
|
||||
```
|
||||
* line one
|
||||
* line two
|
||||
```
|
||||
* line one
|
||||
* line two
|
||||
|
||||
```
|
||||
*incorrect list because there's no space right after the star.
|
||||
```
|
||||
*incorrect list because there's no space right after the star.
|
||||
|
||||
```
|
||||
Below, a line with just one star, must be rendered as is.
|
||||
*
|
||||
```
|
||||
Below, a line with just one star, must be rendered as is.
|
||||
*
|
||||
|
||||
```
|
||||
Below, a line with one star and one space, must be a single <li>
|
||||
*
|
||||
```
|
||||
Below, a line with one star and one space, must be a single <li>
|
||||
*
|
||||
|
||||
```
|
||||
Below, a line with one star and two spaces, must be a single <li>
|
||||
*
|
||||
```
|
||||
Below, a line with one star and two spaces, must be a single <li>
|
||||
*
|
||||
|
||||
```
|
||||
Below, two lines with one star, must be single <li>
|
||||
*
|
||||
*
|
||||
```
|
||||
Below, two lines with one star, must be single <li>
|
||||
*
|
||||
*
|
||||
|
||||
```
|
||||
# h1
|
||||
## h2
|
||||
### h3
|
||||
#### h4 (Should be read as h3)
|
||||
```
|
||||
# h1
|
||||
## h2
|
||||
### h3
|
||||
#### h4 (Should be read as h3)
|
||||
|
||||
Four spaces between the quotes " "
|
||||
```
|
||||
Four spaces between the quotes " ", shrinked in HTML
|
||||
```
|
||||
Four spaces between the quotes " ", shrinked in HTML
|
||||
|
||||
** Text using <b>.
|
||||
```
|
||||
^^^
|
||||
Plain text link: https://website.com/
|
||||
^^^
|
||||
```
|
||||
^^^
|
||||
Plain text link: https://website.com/
|
||||
^^^
|
||||
|
||||
//Text using <i>.
|
||||
~~Text using <del>.
|
||||
__Text using <u>.
|
||||
```
|
||||
Link with double slash: http://truc
|
||||
```
|
||||
Link with double slash: http://truc
|
||||
|
||||
Text having words in **bold**, //italic//, ~~deleted~~, __underlined__.
|
||||
And some other mixed: **//bold italic// ~~bold deleted~~** //~~**italic deleted bold.
|
||||
```
|
||||
^ Link inside a single non-decorated line: http://truc
|
||||
```
|
||||
^ Link inside a single non-decorated line: http://truc
|
||||
|
||||
```
|
||||
Below this line, just "=>" will be ignored and displayed as is.
|
||||
=>
|
||||
```
|
||||
Below this line, just "=> " will be ignored and displayed as is.
|
||||
=>
|
||||
|
||||
```
|
||||
=> gemini://somesite
|
||||
```
|
||||
=> gemini://somesite
|
||||
|
||||
```
|
||||
=> gemini://somesite label of the website
|
||||
```
|
||||
=> gemini://somesite label of the website
|
||||
|
||||
|
||||
|
||||
Du **gras**…
|
||||
Encore du **gras** !
|
||||
|
||||
__This line starts with two _ and none at the end.
|
||||
The formatting stays in the physical line.
|
||||
@ -77,16 +175,12 @@ At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praese
|
||||
>
|
||||
>
|
||||
|
||||
# Unordered list
|
||||
Below, four lines. The first and last won't have a star at the beginning.
|
||||
Line without * at the beginning
|
||||
* line one
|
||||
*line two
|
||||
Line without * at the beginning
|
||||
|
||||
* another first line
|
||||
*another second line
|
||||
|
||||
*single line
|
||||
** Text using <b>.
|
||||
|
||||
//Text using <i>.
|
||||
~~Text using <del>.
|
||||
__Text using <u>.
|
||||
|
||||
Text having words in **bold**, //italic//, ~~deleted~~, __underlined__.
|
||||
And some other mixed: **//bold italic// ~~bold deleted~~** //~~**italic deleted bold.
|
||||
|
Loading…
Reference in New Issue
Block a user