Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert voting information help page to markdown document #1764

Merged
merged 6 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions classes/Renderer/Markdown.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace MySociety\TheyWorkForYou\Renderer;

/**
* Markdown Renderer
*
* Use for converting markdown into help pages.
*/

class Markdown
{
public function markdown_document($this_page){
// This function takes a markdown file and converts it to HTML

$markdown_file = '../../../markdown/' . $this_page . '.md';
$Parsedown = new \Parsedown();

$text = file_get_contents($markdown_file);
$html = $text;
dracos marked this conversation as resolved.
Show resolved Hide resolved
$html = $Parsedown->text($text);

# title is the first h1
preg_match('/<h1>([^<]+)<\/h1>/i', $html, $matches);

$title = $matches[1];

$html = preg_replace_callback('/<h([1-3])>([^<]+)<\/h[1-3]>/i', function($matches) {
dracos marked this conversation as resolved.
Show resolved Hide resolved
$level = $matches[1];
$htitle = $matches[2];
$slug = slugify($htitle);
return "<h$level id=\"$slug\" class=\"js-toc-item\">$htitle</h$level>";
}, $html);

dracos marked this conversation as resolved.
Show resolved Hide resolved

\MySociety\TheyWorkForYou\Renderer::output('static/markdown_template', array(
'html' => $html,
'this_page' => $this_page,
'page_title' => $title,
));

}
}
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"stripe/stripe-php": "^6.10",
"predis/predis": "^1.1",
"volnix/csrf": "^1.2",
"phpmailer/phpmailer": "^6.5"
"phpmailer/phpmailer": "^6.5",
"erusev/parsedown": "^1.7"
},
"require-dev": {
"phpunit/phpunit": "9.*"
Expand Down
52 changes: 51 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

235 changes: 235 additions & 0 deletions markdown/voting-information.md

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions www/docs/voting-information/index.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php

include_once '../../includes/easyparliament/init.php';

$this_page = 'voting-information';
use MySociety\TheyWorkForYou\Renderer\Markdown;

MySociety\TheyWorkForYou\Renderer::output('static/voting_information', array());
$markdown = new Markdown;
$markdown->markdown_document('voting-information');
?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div class="full-page static-page toc-page">
<div class="full-page__row">
<div class="toc-page__col">
<div class="toc js-toc"></div>
</div>
<div class="toc-page__col">

<div class="panel">
<?= $html ?>
</div>
</div>

</div>
</div>
Loading
Loading