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.
|
* manage 404: Display better errors.
|
||||||
* alt texts on pre and quote?
|
* alt texts on pre and quote?
|
||||||
* a way to get the source of a page, using urlrewriting
|
* 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
|
* 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
|
* any error on one read line logs and goes to the next line, resetting modes
|
||||||
* configuration: Fetch configuration in current dir, tries parents.
|
* configuration: Fetch configuration in current dir, tries parents.
|
||||||
@ -19,3 +20,4 @@
|
|||||||
* Be able to navigate (custom the links) when using htmgen.php?url=…
|
* Be able to navigate (custom the links) when using htmgen.php?url=…
|
||||||
* Text localisation
|
* Text localisation
|
||||||
* Search all cases where a narrow no-break space would apply
|
* 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;
|
$mode_textAttributes = true;
|
||||||
foreach ($fileLines as $line) {
|
foreach ($fileLines as $line) {
|
||||||
$reDoCount = 0;
|
$reDoCount = 0;
|
||||||
|
$mode_textAttributes_temp = false;
|
||||||
while (true) {
|
while (true) {
|
||||||
if ($reDoCount>1) die("Too many loops");
|
if ($reDoCount>2) die("Too many loops: ".$mode);
|
||||||
$reDoCount += 1;
|
$reDoCount += 1;
|
||||||
$line1 = substr($line, 0, 1); // $line can be modified
|
$line1 = substr($line, 0, 1); // $line can be modified
|
||||||
$line2 = substr($line, 0, 2); // in the meantime.
|
$line2 = substr($line, 0, 2); // in the meantime.
|
||||||
@ -82,6 +83,16 @@ foreach ($fileLines as $line) {
|
|||||||
if (is_null($mode)) {
|
if (is_null($mode)) {
|
||||||
if (empty($line)) {
|
if (empty($line)) {
|
||||||
echo "<p> </p>\n";
|
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) {
|
} elseif ("#" == $line1) {
|
||||||
preg_match("/^(#{1,3})\s*(.*)/", $line, $sharps);
|
preg_match("/^(#{1,3})\s*(.*)/", $line, $sharps);
|
||||||
$h_level = strlen($sharps[1]);
|
$h_level = strlen($sharps[1]);
|
||||||
@ -93,7 +104,7 @@ foreach ($fileLines as $line) {
|
|||||||
case 3: echo "<h3>".$text."</h3>\n"; break;
|
case 3: echo "<h3>".$text."</h3>\n"; break;
|
||||||
}
|
}
|
||||||
} elseif ("=>" == $line2) {
|
} elseif ("=>" == $line2) {
|
||||||
preg_match("/^=>\s*([^\s]+)(\s+(.*))?$/", $line, $linkParts);
|
if (preg_match("/^=>\s*([^\s]+)(?:\s+(.*))?$/", $line, $linkParts)) {
|
||||||
$url_link = $linkParts[1];
|
$url_link = $linkParts[1];
|
||||||
$url_label = @$linkParts[2];
|
$url_label = @$linkParts[2];
|
||||||
if (empty(trim($url_label))) {
|
if (empty(trim($url_label))) {
|
||||||
@ -103,8 +114,10 @@ foreach ($fileLines as $line) {
|
|||||||
htmlPrepare($url_label);
|
htmlPrepare($url_label);
|
||||||
}
|
}
|
||||||
echo "<p><a href='".$url_link."'>".$url_label."</a></p>\n";
|
echo "<p><a href='".$url_link."'>".$url_label."</a></p>\n";
|
||||||
} elseif ('"""' == $line3) {
|
} else {
|
||||||
$mode_textAttributes = !$mode_textAttributes;
|
$mode = "raw";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
} elseif ("```" == $line3) {
|
} elseif ("```" == $line3) {
|
||||||
$mode="pre";
|
$mode="pre";
|
||||||
echo "<pre>\n";
|
echo "<pre>\n";
|
||||||
@ -117,21 +130,27 @@ foreach ($fileLines as $line) {
|
|||||||
echo "<p> </p>\n";
|
echo "<p> </p>\n";
|
||||||
else
|
else
|
||||||
htmlPrepare($quote);
|
htmlPrepare($quote);
|
||||||
if ($mode_textAttributes) addTextAttributes($line);
|
if ($mode_textAttributes xor $mode_textAttributes_temp) addTextAttributes($line);
|
||||||
echo "<p>".$quote."</p>\n";
|
echo "<p>".$quote."</p>\n";
|
||||||
} elseif ("*" == $line1 && "**" != $line2) {
|
} elseif ("* " == $line2) {
|
||||||
$mode = "ul";
|
|
||||||
echo "<ul>\n";
|
echo "<ul>\n";
|
||||||
|
$mode = "ul";
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
htmlPrepare($line);
|
$mode = "raw";
|
||||||
if ($mode_textAttributes) addTextAttributes($line);
|
continue;
|
||||||
echo "<p>$line</p>\n";
|
|
||||||
}
|
}
|
||||||
|
} 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) {
|
} elseif ("pre"==$mode) {
|
||||||
if ("```" == $line3) {
|
if ("```" == $line3) {
|
||||||
$mode=null;
|
|
||||||
echo "</pre>\n";
|
echo "</pre>\n";
|
||||||
|
$mode = null;
|
||||||
} else {
|
} else {
|
||||||
htmlPrepare($line);
|
htmlPrepare($line);
|
||||||
echo $line."\n";
|
echo $line."\n";
|
||||||
@ -146,27 +165,31 @@ foreach ($fileLines as $line) {
|
|||||||
htmlPrepare($quote);
|
htmlPrepare($quote);
|
||||||
echo "<p>".$quote."</p>\n";
|
echo "<p>".$quote."</p>\n";
|
||||||
} else {
|
} else {
|
||||||
$mode=null;
|
|
||||||
echo "</blockquote>\n";
|
echo "</blockquote>\n";
|
||||||
|
$mode = null;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} elseif ("ul"==$mode) {
|
} elseif ("ul"==$mode) {
|
||||||
if ("*" == $line1 && "**" != $line2) {
|
if ("* " == $line2) {
|
||||||
preg_match("/^\*\s*(.*)$/", $line, $ulParts);
|
preg_match("/^\*\s*(.*)$/", $line, $ulParts);
|
||||||
$li = $ulParts[1];
|
$li = $ulParts[1];
|
||||||
if (empty($li))
|
if (empty($li)) {
|
||||||
echo "<li> \n";
|
echo "<li> \n";
|
||||||
else
|
|
||||||
htmlPrepare($li);
|
|
||||||
addTextAttributes($li);
|
|
||||||
echo "<li>".$li."\n";
|
|
||||||
} else {
|
} else {
|
||||||
$mode = null;
|
htmlPrepare($li);
|
||||||
|
if ($mode_textAttributes xor $mode_textAttributes_temp) addTextAttributes($line);
|
||||||
|
echo "<li>".$li."\n";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
echo "</ul>\n";
|
echo "</ul>\n";
|
||||||
|
$mode = null;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
die("Unexpected mode: $mode!");
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
|
break; // exits the while(true) as no continue occured
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$body = ob_get_contents();
|
$body = ob_get_contents();
|
||||||
|
128
tests/test.gmi
128
tests/test.gmi
@ -1,19 +1,117 @@
|
|||||||
# Test page
|
# 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
|
## h2
|
||||||
### h3
|
### h3
|
||||||
#### h4 (Should be read as 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>.
|
Link with double slash: http://truc
|
||||||
__Text using <u>.
|
```
|
||||||
|
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.
|
__This line starts with two _ and none at the end.
|
||||||
The formatting stays in the physical line.
|
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
|
** Text using <b>.
|
||||||
*another second line
|
|
||||||
|
|
||||||
*single line
|
|
||||||
|
|
||||||
|
//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