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

Feature/issue 1255 admin view mobile #1260

Merged
Merged
Changes from all 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
72 changes: 44 additions & 28 deletions Modules/admin/admin_main_view.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ function markdownStringify(md) {
// indent values
.replace(/\:-/g,':\t')
// start titles on new lines
.replace(/- \*\*/g,'\n\t')
.replace(/- \*\*/g,'\t')
// remove bold
.replace(/\*\*/g,'')
// remove heading
Expand All @@ -477,34 +477,44 @@ function markdownStringify(md) {
}
/**
* attempt to convert <html> to markdown (text/markdown)
*
* uses `====` as temp tab placeholder
* uses `~~~~` as temp newline placeholder
* @todo: look at a better library to do this
*/
function markdownify(markup) {
var newline = '~~~~';
var indent = '====';

var newlineRegex = new RegExp(newline,'g');
var indentRegex = new RegExp(indent,'g');

// add placeholder for nested <dl> <dd> <dl>
// -----
let $temp = $('<div>');
$temp.html(markup);
let $nestedLists = $temp.find('dl.inline');
$nestedLists.each(function(i, elem){
let $list = $(elem);
let $value = $list.find('dd:last');
// include placeholder to insert new line below sub list
$value.html($value.html() + '\n~~');

// include placeholder to indent sub items
$list.find('dd').each(function(j, elem2){
let $value = $(elem2);
let $title = $value.prev('dt');
$title.html('====' + $title.html());
})

// add correct indentation to nested lists
$temp.find('dl').each(function(i, parent){
let $parent = $(parent);
if(!$parent.is('.inline')) {
$(parent).find('dl').each(function(i, child){
let $list = $(child);
let $firstTitle = $list.find('dt').first();
$firstTitle.before(newline)
$list.find('dt').each(function(j, title){
let $title = $(title)
$title.before(indent)
})
})
}
})

// -----

// use modified <html> source to replace patterns
markup = $temp.html()
return markup

return markup
// remove indenting
.replace(/^\s{2,}/gm," ")
// remove buttons
Expand All @@ -514,34 +524,40 @@ function markdownify(markup) {
// remove comments
.replace(/<!--[\S\s]*-->/g,'')
// replace <h4> with markdown level two heading (##)
.replace(/\s+<h4 *[^/]*?>/g,"~~## ")
.replace(/\s+<h4 *[^/]*?>/g, newline+newline+"## ")
.replace(/<\/h4>\s+/g,"\n")
.replace(/<dd class="__inline__">/g,' ')
// remove <dl>
.replace(/<dl *[^/]*?>/g," ")
.replace(/<\/dl>[ \n]/g,"\n~~")
.replace(/<\/dl>[ \n]/g,"\n" + newline)
// remove <dt>
.replace(/<dt *[^/]*?>/g,' - **')
.replace(/<\/dt>[ \n]*/g,'**')
// remove <dd>
.replace(/<dd *[^/]*?>/g,' :- ')
.replace(/<\/dd>/g,"\n")
// mark bold content
.replace(/<strong *[^/]*?>/g,'**')
.replace(/<\/strong>[ \n]*/g,'** ')
// remove all other <tags>
.replace(/(<([^>]+)> *)/ig,'')
// remove indenting
// remove all indenting
.replace(/^ {2,}/gm," ")
// remove orphan new lines
.replace(/\n{3,}/g,"\n\n")
// remove all single space indents
.replace(/^ (\S)/gm,"$1")
// replace indent placeholder
.replace(/ - \*\*====/g,' - **')
// remove empty title/value seperator
// .replace(/\|\s{2,}-/g, '\n')
.replace(indentRegex,' ')
// remove orphan new lines
.replace(/\n \n ?\n/g, '\n')
// remove leading spaces from values
.replace(/:-\s+/g,':- ')
// remove placeholder
.replace(/\~~/g,"\n")
// replace newline placeholder
.replace(newlineRegex,"\n")
// remove orphan new lines
.replace(/\n{2,} /g,"\n\n")
.replace(/\n{3,}/g,"\n\n")
// add newline before level 2 title
.replace(/\n?##/g,'\n##')
.trim()
}
/**
Expand Down Expand Up @@ -692,8 +708,8 @@ function refresh_log(result){
// display content in container and scroll to the bottom
function output_logfile(result, $container){
$container.html(result);
scrollable = $container.parent()[0];
scrollable.scrollTop = scrollable.scrollHeight;
scrollable = $container.parent('pre')[0];
if(scrollable) scrollable.scrollTop = scrollable.scrollHeight;
}

getLog();
Expand Down