-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Source voting information from markdown document
- Loading branch information
Showing
5 changed files
with
296 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
$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) { | ||
$level = $matches[1]; | ||
$htitle = $matches[2]; | ||
$slug = slugify($htitle); | ||
return "<h$level id=\"$slug\" class=\"js-toc-item\">$htitle</h$level>"; | ||
}, $html); | ||
|
||
|
||
\MySociety\TheyWorkForYou\Renderer::output('static/markdown_template', array( | ||
'html' => $html, | ||
'this_page' => $this_page, | ||
'page_title' => $title, | ||
)); | ||
|
||
} | ||
} |
Oops, something went wrong.