mirror of
https://tildegit.org/sbgodin/HtmGem.git
synced 2023-08-25 13:53:12 +02:00
WIP
This commit is contained in:
parent
1da3f6520b
commit
b2d5ecf990
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
*.swp
|
1
TODO
1
TODO
@ -11,3 +11,4 @@
|
||||
* On links indicate whether it's on Gemini or Www or image.
|
||||
* Command line API for script and testing.
|
||||
* Manage bold, italic, underline on one physical line.
|
||||
* Prevent infinite loop if errors occurs with reDo
|
||||
|
16
htmgem.php
16
htmgem.php
@ -39,12 +39,22 @@ echo(<<<EOL
|
||||
<body>
|
||||
EOL);
|
||||
|
||||
function addTextAttributes($line) {
|
||||
$output = $line;
|
||||
$output = preg_replace("#__([^_]+)(?:__)?#", "<u>\$1</u>", $output);
|
||||
$output = preg_replace("#//([^/]+)(?://)?#", "<i>\$1</i>", $output);
|
||||
$output = preg_replace("#~~([^~]+)(?:~~)?#", "<del>\$1</del>", $output);
|
||||
$output = preg_replace("#\*\*([^\*]+)(?:\*\*)?#", "<b>\$1</b>", $output);
|
||||
return $output;
|
||||
}
|
||||
|
||||
$mode = null;
|
||||
foreach ($fileLines as $line) {
|
||||
$reDo = true;
|
||||
$line1 = substr($line, 0, 1);
|
||||
$line2 = substr($line, 0, 2);
|
||||
$line3 = substr($line, 0, 3);
|
||||
$line = htmlspecialchars($line, ENT_HTML5, "UTF-8", false);
|
||||
while ($reDo) {
|
||||
$reDo = false; # Change in modes need to redo one loop as they can’t handle the case
|
||||
if (is_null($mode)) {
|
||||
@ -77,12 +87,12 @@ foreach ($fileLines as $line) {
|
||||
print("<p> </p>\n");
|
||||
else
|
||||
print("<p>".$quoteParts[1]."</p>\n");
|
||||
} elseif ("*" == $line1) {
|
||||
} elseif ("*" == $line1 && "**" != $line2) {
|
||||
$mode = "ul";
|
||||
$reDo = true;
|
||||
print("<ul>\n");
|
||||
} else {
|
||||
print("<p>".$line."</p>\n");
|
||||
print("<p>".addTextAttributes($line)."</p>\n");
|
||||
}
|
||||
} elseif ("pre"==$mode) {
|
||||
if ("```" == $line3) {
|
||||
@ -105,7 +115,7 @@ foreach ($fileLines as $line) {
|
||||
$reDo=true;
|
||||
}
|
||||
} elseif ("ul"==$mode) {
|
||||
if ("*" == $line1) {
|
||||
if ("*" == $line1 && "**" != $line2) {
|
||||
preg_match("/^\*\s*(.*)$/", $line, $ulParts);
|
||||
$li = $ulParts[1];
|
||||
if (empty($li))
|
||||
|
@ -4,6 +4,15 @@
|
||||
### h3
|
||||
#### h4 (Should be read as h3)
|
||||
|
||||
**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 AND //bold italic// and ~~bold deleted~~**.
|
||||
|
||||
Text attributes __underlined, plus ~~deleted having underlined stop now__ then deleted after~~.
|
||||
|
||||
Below, headers with spaces at the beginning of the line:
|
||||
# Missed h1, there's a space as a first character.
|
||||
@ -62,9 +71,11 @@ 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
|
||||
|
Loading…
Reference in New Issue
Block a user