diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2023-03-02 02:17:52 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2023-03-02 02:17:52 +0300 |
commit | 917d2622aa5fe748c1cda914eae94c12be743c42 (patch) | |
tree | 946d30723c32e0834eb7a74bfa7cb766d22bbd2a | |
parent | 6daf574fd3f18909be05b0d61335e7634329ec45 (diff) |
support tables and emojies in markdown
-rw-r--r-- | composer.json | 15 | ||||
-rw-r--r-- | composer.lock | 321 | ||||
-rw-r--r-- | engine/database/MySQLConnection.php | 5 | ||||
-rw-r--r-- | htdocs/scss/app/blog.scss | 15 | ||||
-rw-r--r-- | lib/MyParsedown.php | 11 | ||||
-rw-r--r-- | mysql_schema.sql | 32 |
6 files changed, 196 insertions, 203 deletions
diff --git a/composer.json b/composer.json index 305e87d..5bdc23d 100644 --- a/composer.json +++ b/composer.json @@ -1,13 +1,24 @@ { "require": { - "sixlive/parsedown-highlight": "^0.3.1", - "erusev/parsedown": "1.8.0-beta-5", + "gch1p/parsedown-highlight": "master", + "gch1p/parsedown-highlight-extended": "dev-main", + "erusev/parsedown": "1.8.0-beta-7", "ext-mbstring": "*", "ext-gd": "*", "ext-mysqli": "*", "ext-json": "*", "ext-sqlite3": "*" }, + "repositories": [ + { + "url": "https://github.com/gch1p/parsedown-highlight", + "type": "git" + }, + { + "url": "https://github.com/gch1p/ParsedownHighlightExtended", + "type": "git" + } + ], "minimum-stability": "dev", "prefer-stable": true, "preferred-install": "dist" diff --git a/composer.lock b/composer.lock index c196297..ad2c703 100644 --- a/composer.lock +++ b/composer.lock @@ -4,64 +4,20 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "cfed6325222efab0afd48dc69b6dd69b", + "content-hash": "5a615af5a232dca9e536bd9217d54be6", "packages": [ { - "name": "bhaktaraz/php-rss-generator", - "version": "dev-master", - "source": { - "type": "git", - "url": "https://github.com/bhaktaraz/php-rss-generator.git", - "reference": "4c90e6e2fbb74f0dcb3cf6d1fcd4fa1a77b53f0d" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/bhaktaraz/php-rss-generator/zipball/4c90e6e2fbb74f0dcb3cf6d1fcd4fa1a77b53f0d", - "reference": "4c90e6e2fbb74f0dcb3cf6d1fcd4fa1a77b53f0d", - "shasum": "" - }, - "require": { - "php": ">=5.3.0" - }, - "type": "library", - "autoload": { - "psr-4": { - "Bhaktaraz\\RSSGenerator\\": "Source/Bhaktaraz/RSSGenerator/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Bhaktaraz Bhatta", - "email": "bhattabhakta@gmail.com" - } - ], - "description": "Simple RSS generator library for PHP 5.5 or later.", - "homepage": "https://github.com/bhaktaraz/php-rss-generator", - "keywords": [ - "Facebook product feed generator", - "feed", - "generator", - "rss", - "writer" - ], - "time": "2019-01-08T12:17:22+00:00" - }, - { "name": "erusev/parsedown", - "version": "1.8.0-beta-5", + "version": "1.8.0-beta-7", "source": { "type": "git", "url": "https://github.com/erusev/parsedown.git", - "reference": "c26a2ee4bf8ba0270daab7da0353f2525ca6564a" + "reference": "fe7a50eceb4a3c867cc9fa9c0aa906b1067d1955" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/erusev/parsedown/zipball/c26a2ee4bf8ba0270daab7da0353f2525ca6564a", - "reference": "c26a2ee4bf8ba0270daab7da0353f2525ca6564a", + "url": "https://api.github.com/repos/erusev/parsedown/zipball/fe7a50eceb4a3c867cc9fa9c0aa906b1067d1955", + "reference": "fe7a50eceb4a3c867cc9fa9c0aa906b1067d1955", "shasum": "" }, "require": { @@ -94,91 +50,75 @@ "markdown", "parser" ], - "time": "2018-06-11T18:15:32+00:00" + "support": { + "issues": "https://github.com/erusev/parsedown/issues", + "source": "https://github.com/erusev/parsedown/tree/1.8.0-beta-7" + }, + "time": "2019-03-17T18:47:21+00:00" }, { - "name": "scrivo/highlight.php", - "version": "v9.15.8.0", + "name": "erusev/parsedown-extra", + "version": "0.8.1", "source": { "type": "git", - "url": "https://github.com/scrivo/highlight.php.git", - "reference": "2626bf8731737b2487e54bda5a980f0e5a143320" + "url": "https://github.com/erusev/parsedown-extra.git", + "reference": "91ac3ff98f0cea243bdccc688df43810f044dcef" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/scrivo/highlight.php/zipball/2626bf8731737b2487e54bda5a980f0e5a143320", - "reference": "2626bf8731737b2487e54bda5a980f0e5a143320", + "url": "https://api.github.com/repos/erusev/parsedown-extra/zipball/91ac3ff98f0cea243bdccc688df43810f044dcef", + "reference": "91ac3ff98f0cea243bdccc688df43810f044dcef", "shasum": "" }, "require": { - "ext-json": "*", - "ext-mbstring": "*" + "erusev/parsedown": "^1.7.4" }, "require-dev": { - "phpunit/phpunit": "^4.8|^5.7", - "symfony/finder": "^2.8" - }, - "suggest": { - "ext-dom": "Needed to make use of the features in the utilities namespace" + "phpunit/phpunit": "^4.8.35" }, "type": "library", "autoload": { "psr-0": { - "Highlight\\": "", - "HighlightUtilities\\": "" - }, - "files": [ - "HighlightUtilities/functions.php" - ] + "ParsedownExtra": "" + } }, "notification-url": "https://packagist.org/downloads/", "license": [ - "BSD-3-Clause" + "MIT" ], "authors": [ { - "name": "Geert Bergman", - "homepage": "http://www.scrivo.org/", - "role": "Project Author" - }, - { - "name": "Vladimir Jimenez", - "homepage": "https://allejo.io", - "role": "Contributor" - }, - { - "name": "Martin Folkers", - "homepage": "https://twobrain.io", - "role": "Contributor" + "name": "Emanuil Rusev", + "email": "hello@erusev.com", + "homepage": "http://erusev.com" } ], - "description": "Server side syntax highlighter that supports 185 languages. It's a PHP port of highlight.js", + "description": "An extension of Parsedown that adds support for Markdown Extra.", + "homepage": "https://github.com/erusev/parsedown-extra", "keywords": [ - "code", - "highlight", - "highlight.js", - "highlight.php", - "syntax" + "markdown", + "markdown extra", + "parsedown", + "parser" ], - "time": "2019-05-31T06:24:05+00:00" + "support": { + "issues": "https://github.com/erusev/parsedown-extra/issues", + "source": "https://github.com/erusev/parsedown-extra/tree/0.8.x" + }, + "time": "2019-12-30T23:20:37+00:00" }, { - "name": "sixlive/parsedown-highlight", - "version": "v0.3.1", + "name": "gch1p/parsedown-highlight", + "version": "dev-master", "source": { "type": "git", - "url": "https://github.com/sixlive/parsedown-highlight.git", - "reference": "e05632eea4cf97c865a17d2b65f31c5b477a6a7a" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sixlive/parsedown-highlight/zipball/e05632eea4cf97c865a17d2b65f31c5b477a6a7a", - "reference": "e05632eea4cf97c865a17d2b65f31c5b477a6a7a", - "shasum": "" + "url": "https://github.com/gch1p/parsedown-highlight", + "reference": "d017545cc221f4becac0f7fc0570304ceabba846" }, "require": { - "erusev/parsedown": "1.8.0-beta-5", - "php": "^7.1|7.2", + "erusev/parsedown": "1.8.0-beta-7", + "erusev/parsedown-extra": "0.8.1", + "php": ">=7.1", "scrivo/highlight.php": "^9.14" }, "require-dev": { @@ -187,13 +127,29 @@ "phpunit/phpunit": "^6.0|^7.0", "sempro/phpunit-pretty-print": "^1.0" }, + "default-branch": true, "type": "library", "autoload": { "psr-4": { - "sixlive\\": "src" + "gch1p\\": "src" } }, - "notification-url": "https://packagist.org/downloads/", + "autoload-dev": { + "psr-4": { + "Tests\\": "tests" + } + }, + "scripts": { + "test": [ + "phpunit" + ], + "styles:lint": [ + "php-cs-fixer fix --dry-run --diff" + ], + "styles:fix": [ + "php-cs-fixer fix" + ] + }, "license": [ "MIT" ], @@ -206,107 +162,89 @@ } ], "description": "Server side code block rendering for Parsedown", - "homepage": "https://github.com/sixlive/parsedown-highlight", + "homepage": "https://github.com/gch1p/parsedown-highlight", "keywords": [ "code", "markdown", "parsedown" ], - "time": "2019-04-14T15:21:19+00:00" + "time": "2023-03-01T22:25:56+00:00" }, { - "name": "symfony/polyfill-ctype", - "version": "v1.11.0", + "name": "gch1p/parsedown-highlight-extended", + "version": "dev-main", "source": { "type": "git", - "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "82ebae02209c21113908c229e9883c419720738a" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/82ebae02209c21113908c229e9883c419720738a", - "reference": "82ebae02209c21113908c229e9883c419720738a", - "shasum": "" + "url": "https://github.com/gch1p/ParsedownHighlightExtended", + "reference": "e2d9d7eae203680690d61877fbef2dc2df61dd0b" }, "require": { - "php": ">=5.3.3" - }, - "suggest": { - "ext-ctype": "For best performance" + "erusev/parsedown": "^1.8-beta-6", + "erusev/parsedown-extra": "^0.8.0", + "gch1p/parsedown-highlight": "master", + "php": ">=7.2" }, + "default-branch": true, "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.11-dev" - } - }, "autoload": { - "psr-4": { - "Symfony\\Polyfill\\Ctype\\": "" - }, - "files": [ - "bootstrap.php" - ] + "psr-0": { + "ParsedownExtended": "" + } }, - "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], "authors": [ { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - }, - { - "name": "Gert de Pagter", - "email": "BackEndTea@gmail.com" + "name": "Benjamin Hoegh", + "homepage": "https://github.com/benjaminhoegh" } ], - "description": "Symfony polyfill for ctype functions", - "homepage": "https://symfony.com", + "description": "An extension for ParsedownHighlight.", + "homepage": "https://github.com/gch1p/ParsedownHighlightExtended", "keywords": [ - "compatibility", - "ctype", - "polyfill", - "portable" + "markdown", + "markdown extended", + "parsedown", + "parsedown extended" ], - "time": "2019-02-06T07:57:58+00:00" + "time": "2023-03-01T22:30:01+00:00" }, { - "name": "twig/twig", - "version": "v1.42.1", + "name": "scrivo/highlight.php", + "version": "v9.18.1.10", "source": { "type": "git", - "url": "https://github.com/twigphp/Twig.git", - "reference": "671347603760a88b1e7288aaa9378f33687d7edf" + "url": "https://github.com/scrivo/highlight.php.git", + "reference": "850f4b44697a2552e892ffe71490ba2733c2fc6e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/671347603760a88b1e7288aaa9378f33687d7edf", - "reference": "671347603760a88b1e7288aaa9378f33687d7edf", + "url": "https://api.github.com/repos/scrivo/highlight.php/zipball/850f4b44697a2552e892ffe71490ba2733c2fc6e", + "reference": "850f4b44697a2552e892ffe71490ba2733c2fc6e", "shasum": "" }, "require": { - "php": ">=5.4.0", - "symfony/polyfill-ctype": "^1.8" + "ext-json": "*", + "php": ">=5.4" }, "require-dev": { - "psr/container": "^1.0", - "symfony/debug": "^2.7", - "symfony/phpunit-bridge": "^3.4.19|^4.1.8|^5.0" + "phpunit/phpunit": "^4.8|^5.7", + "sabberworm/php-css-parser": "^8.3", + "symfony/finder": "^2.8|^3.4|^5.4", + "symfony/var-dumper": "^2.8|^3.4|^5.4" }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.42-dev" - } + "suggest": { + "ext-mbstring": "Allows highlighting code with unicode characters and supports language with unicode keywords" }, + "type": "library", "autoload": { + "files": [ + "HighlightUtilities/functions.php" + ], "psr-0": { - "Twig_": "lib/" - }, - "psr-4": { - "Twig\\": "src/" + "Highlight\\": "", + "HighlightUtilities\\": "" } }, "notification-url": "https://packagist.org/downloads/", @@ -315,38 +253,57 @@ ], "authors": [ { - "name": "Fabien Potencier", - "email": "fabien@symfony.com", - "homepage": "http://fabien.potencier.org", - "role": "Lead Developer" + "name": "Geert Bergman", + "homepage": "http://www.scrivo.org/", + "role": "Project Author" }, { - "name": "Armin Ronacher", - "email": "armin.ronacher@active-4.com", - "role": "Project Founder" + "name": "Vladimir Jimenez", + "homepage": "https://allejo.io", + "role": "Maintainer" }, { - "name": "Twig Team", - "homepage": "https://twig.symfony.com/contributors", - "role": "Contributors" + "name": "Martin Folkers", + "homepage": "https://twobrain.io", + "role": "Contributor" } ], - "description": "Twig, the flexible, fast, and secure template language for PHP", - "homepage": "https://twig.symfony.com", + "description": "Server side syntax highlighter that supports 185 languages. It's a PHP port of highlight.js", "keywords": [ - "templating" + "code", + "highlight", + "highlight.js", + "highlight.php", + "syntax" + ], + "support": { + "issues": "https://github.com/scrivo/highlight.php/issues", + "source": "https://github.com/scrivo/highlight.php" + }, + "funding": [ + { + "url": "https://github.com/allejo", + "type": "github" + } ], - "time": "2019-06-04T11:31:08+00:00" + "time": "2022-12-17T21:53:22+00:00" } ], "packages-dev": [], "aliases": [], "minimum-stability": "dev", "stability-flags": { - "bhaktaraz/php-rss-generator": 20 + "gch1p/parsedown-highlight-extended": 20 }, "prefer-stable": true, "prefer-lowest": false, - "platform": [], - "platform-dev": [] + "platform": { + "ext-mbstring": "*", + "ext-gd": "*", + "ext-mysqli": "*", + "ext-json": "*", + "ext-sqlite3": "*" + }, + "platform-dev": [], + "plugin-api-version": "2.3.0" } diff --git a/engine/database/MySQLConnection.php b/engine/database/MySQLConnection.php index 9b473cb..c4e47e5 100644 --- a/engine/database/MySQLConnection.php +++ b/engine/database/MySQLConnection.php @@ -17,7 +17,10 @@ class MySQLConnection extends CommonDatabase { public function connect(): bool { $this->link = new mysqli(); - return !!$this->link->real_connect($this->host, $this->user, $this->password, $this->database); + $result = $this->link->real_connect($this->host, $this->user, $this->password, $this->database); + if ($result) + $this->link->set_charset('utf8mb4'); + return !!$result; } public function query(string $sql, ...$args): mysqli_result|bool { diff --git a/htdocs/scss/app/blog.scss b/htdocs/scss/app/blog.scss index 53ec7e4..da640f9 100644 --- a/htdocs/scss/app/blog.scss +++ b/htdocs/scss/app/blog.scss @@ -180,6 +180,21 @@ color: $grey; } + table { + border-collapse: collapse; + border: 1px $border-color solid; + } + table thead td { + font-weight: bold; + } + table td, table th { + padding: 7px; + border: 1px $border-color solid; + } + table th { + padding-right: 12px; + } + table.table-100 { border-collapse: collapse; border: 0; diff --git a/lib/MyParsedown.php b/lib/MyParsedown.php index 11e86d6..cd537bc 100644 --- a/lib/MyParsedown.php +++ b/lib/MyParsedown.php @@ -1,13 +1,16 @@ <?php -use sixlive\ParsedownHighlight; - -class MyParsedown extends ParsedownHighlight { +class MyParsedown extends ParsedownExtended { public function __construct( protected bool $useImagePreviews = false ) { - parent::__construct(); + parent::__construct([ + 'tables' => [ + 'tablespan' => true + ] + ]); + $this->InlineTypes['{'][] = 'FileAttach'; $this->InlineTypes['{'][] = 'Image'; $this->InlineTypes['{'][] = 'Video'; diff --git a/mysql_schema.sql b/mysql_schema.sql index 68c9479..fa5459b 100644 --- a/mysql_schema.sql +++ b/mysql_schema.sql @@ -22,24 +22,28 @@ CREATE TABLE `config` ( CREATE TABLE `pages` ( `short_name` char(64) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL, `title` char(255) NOT NULL, - `md` text NOT NULL DEFAULT '', - `html` text NOT NULL DEFAULT '', - `ts` int(10) UNSIGNED NOT NULL DEFAULT 0, - `update_ts` int(10) UNSIGNED NOT NULL DEFAULT 0, - `visible` tinyint(3) UNSIGNED NOT NULL DEFAULT 0 + `md` text CHARACTER SET utf8mb4 NOT NULL DEFAULT '\'\'', + `html` text CHARACTER SET utf8mb4 NOT NULL DEFAULT '\'\'', + `ts` int(10) unsigned NOT NULL DEFAULT 0, + `update_ts` int(10) unsigned NOT NULL DEFAULT 0, + `visible` tinyint(3) unsigned NOT NULL DEFAULT 0, + PRIMARY KEY (`short_name`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `posts` ( - `id` int(10) UNSIGNED NOT NULL, + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `title` char(255) NOT NULL, - `md` text NOT NULL, - `html` text NOT NULL, - `text` text NOT NULL, - `ts` int(10) UNSIGNED NOT NULL DEFAULT 0, - `update_ts` int(10) UNSIGNED NOT NULL DEFAULT 0, - `visible` tinyint(1) UNSIGNED NOT NULL DEFAULT 0, - `short_name` char(64) NOT NULL -) ENGINE=InnoDB DEFAULT CHARSET=utf8; + `md` text CHARACTER SET utf8mb4 NOT NULL, + `html` text CHARACTER SET utf8mb4 NOT NULL, + `text` text CHARACTER SET utf8mb4 NOT NULL, + `ts` int(10) unsigned NOT NULL DEFAULT 0, + `update_ts` int(10) unsigned NOT NULL DEFAULT 0, + `visible` tinyint(1) unsigned NOT NULL DEFAULT 0, + `short_name` char(64) NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `short_name` (`short_name`), + KEY ` visible_ts_idx` (`visible`,`ts`) +) ENGINE=InnoDB AUTO_INCREMENT=66 DEFAULT CHARSET=utf8; CREATE TABLE `posts_tags` ( `id` int(11) NOT NULL, |