Phi: interprete aircraft help as markdown
This commit is contained in:
parent
e2df2c3c6b
commit
9d2dd4df06
7 changed files with 4017 additions and 3 deletions
32
webgui/3rdparty/pagedown/LICENSE.txt
vendored
Normal file
32
webgui/3rdparty/pagedown/LICENSE.txt
vendored
Normal file
|
@ -0,0 +1,32 @@
|
|||
A javascript port of Markdown, as used on Stack Overflow
|
||||
and the rest of Stack Exchange network.
|
||||
|
||||
Largely based on showdown.js by John Fraser (Attacklab).
|
||||
|
||||
Original Markdown Copyright (c) 2004-2005 John Gruber
|
||||
<http://daringfireball.net/projects/markdown/>
|
||||
|
||||
|
||||
Original Showdown code copyright (c) 2007 John Fraser
|
||||
|
||||
Modifications and bugfixes (c) 2009 Dana Robinson
|
||||
Modifications and bugfixes (c) 2009-2014 Stack Exchange Inc.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
1627
webgui/3rdparty/pagedown/Markdown.Converter.js
vendored
Normal file
1627
webgui/3rdparty/pagedown/Markdown.Converter.js
vendored
Normal file
File diff suppressed because it is too large
Load diff
2243
webgui/3rdparty/pagedown/Markdown.Editor.js
vendored
Normal file
2243
webgui/3rdparty/pagedown/Markdown.Editor.js
vendored
Normal file
File diff suppressed because it is too large
Load diff
108
webgui/3rdparty/pagedown/Markdown.Sanitizer.js
vendored
Normal file
108
webgui/3rdparty/pagedown/Markdown.Sanitizer.js
vendored
Normal file
|
@ -0,0 +1,108 @@
|
|||
(function () {
|
||||
var output, Converter;
|
||||
if (typeof exports === "object" && typeof require === "function") { // we're in a CommonJS (e.g. Node.js) module
|
||||
output = exports;
|
||||
Converter = require("./Markdown.Converter").Converter;
|
||||
} else {
|
||||
output = window.Markdown;
|
||||
Converter = output.Converter;
|
||||
}
|
||||
|
||||
output.getSanitizingConverter = function () {
|
||||
var converter = new Converter();
|
||||
converter.hooks.chain("postConversion", sanitizeHtml);
|
||||
converter.hooks.chain("postConversion", balanceTags);
|
||||
return converter;
|
||||
}
|
||||
|
||||
function sanitizeHtml(html) {
|
||||
return html.replace(/<[^>]*>?/gi, sanitizeTag);
|
||||
}
|
||||
|
||||
// (tags that can be opened/closed) | (tags that stand alone)
|
||||
var basic_tag_whitelist = /^(<\/?(b|blockquote|code|del|dd|dl|dt|em|h1|h2|h3|i|kbd|li|ol(?: start="\d+")?|p|pre|s|sup|sub|strong|strike|ul)>|<(br|hr)\s?\/?>)$/i;
|
||||
// <a href="url..." optional title>|</a>
|
||||
var a_white = /^(<a\shref="((https?|ftp):\/\/|\/)[-A-Za-z0-9+&@#\/%?=~_|!:,.;\(\)*[\]$]+"(\stitle="[^"<>]+")?\s?>|<\/a>)$/i;
|
||||
|
||||
// <img src="url..." optional width optional height optional alt optional title
|
||||
var img_white = /^(<img\ssrc="(https?:\/\/|\/)[-A-Za-z0-9+&@#\/%?=~_|!:,.;\(\)*[\]$]+"(\swidth="\d{1,3}")?(\sheight="\d{1,3}")?(\salt="[^"<>]*")?(\stitle="[^"<>]*")?\s?\/?>)$/i;
|
||||
|
||||
function sanitizeTag(tag) {
|
||||
if (tag.match(basic_tag_whitelist) || tag.match(a_white) || tag.match(img_white))
|
||||
return tag;
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// attempt to balance HTML tags in the html string
|
||||
/// by removing any unmatched opening or closing tags
|
||||
/// IMPORTANT: we *assume* HTML has *already* been
|
||||
/// sanitized and is safe/sane before balancing!
|
||||
///
|
||||
/// adapted from CODESNIPPET: A8591DBA-D1D3-11DE-947C-BA5556D89593
|
||||
/// </summary>
|
||||
function balanceTags(html) {
|
||||
|
||||
if (html == "")
|
||||
return "";
|
||||
|
||||
var re = /<\/?\w+[^>]*(\s|$|>)/g;
|
||||
// convert everything to lower case; this makes
|
||||
// our case insensitive comparisons easier
|
||||
var tags = html.toLowerCase().match(re);
|
||||
|
||||
// no HTML tags present? nothing to do; exit now
|
||||
var tagcount = (tags || []).length;
|
||||
if (tagcount == 0)
|
||||
return html;
|
||||
|
||||
var tagname, tag;
|
||||
var ignoredtags = "<p><img><br><li><hr>";
|
||||
var match;
|
||||
var tagpaired = [];
|
||||
var tagremove = [];
|
||||
var needsRemoval = false;
|
||||
|
||||
// loop through matched tags in forward order
|
||||
for (var ctag = 0; ctag < tagcount; ctag++) {
|
||||
tagname = tags[ctag].replace(/<\/?(\w+).*/, "$1");
|
||||
// skip any already paired tags
|
||||
// and skip tags in our ignore list; assume they're self-closed
|
||||
if (tagpaired[ctag] || ignoredtags.search("<" + tagname + ">") > -1)
|
||||
continue;
|
||||
|
||||
tag = tags[ctag];
|
||||
match = -1;
|
||||
|
||||
if (!/^<\//.test(tag)) {
|
||||
// this is an opening tag
|
||||
// search forwards (next tags), look for closing tags
|
||||
for (var ntag = ctag + 1; ntag < tagcount; ntag++) {
|
||||
if (!tagpaired[ntag] && tags[ntag] == "</" + tagname + ">") {
|
||||
match = ntag;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (match == -1)
|
||||
needsRemoval = tagremove[ctag] = true; // mark for removal
|
||||
else
|
||||
tagpaired[match] = true; // mark paired
|
||||
}
|
||||
|
||||
if (!needsRemoval)
|
||||
return html;
|
||||
|
||||
// delete all orphaned tags from the string
|
||||
|
||||
var ctag = 0;
|
||||
html = html.replace(re, function (match) {
|
||||
var res = tagremove[ctag] ? "" : match;
|
||||
ctag++;
|
||||
return res;
|
||||
});
|
||||
return html;
|
||||
}
|
||||
})();
|
|
@ -15,6 +15,7 @@ require.config({
|
|||
props : 'lib/props2',
|
||||
sammy: '3rdparty/sammy-latest.min',
|
||||
aircraft: '../aircraft-dir',
|
||||
pagedown: '3rdparty/pagedown'
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
<tbody data-bind="foreach: helpContent">
|
||||
<tr>
|
||||
<!-- ko if: $data.type == 'line' || $data.type == 'text' -->
|
||||
<td colspan="2" data-bind="text: $data.text"></td>
|
||||
<td colspan="2" data-bind="html: $data.text"></td>
|
||||
<!-- /ko -->
|
||||
<!-- ko if: $data.type == 'key' -->
|
||||
<td><span>Key</span><span data-bind="text: $data.name" style="padding: 0 1em 0 0.5em; font-weight: bold;"></span></td>
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
define([
|
||||
'jquery', 'knockout', 'text!./Help.html'
|
||||
'jquery', 'knockout', 'text!./Help.html', 'pagedown/Markdown.Converter'
|
||||
], function(jquery, ko, htmlString) {
|
||||
|
||||
var converter = new Markdown.Converter();
|
||||
|
||||
function ViewModel(params) {
|
||||
var self = this;
|
||||
|
||||
|
@ -31,7 +34,7 @@ define([
|
|||
} else if (prop.name == 'text') {
|
||||
helpContent.push({
|
||||
type: 'text',
|
||||
text: prop.value,
|
||||
text: converter.makeHtml(prop.value),
|
||||
});
|
||||
} else if (prop.name == 'key') {
|
||||
var content = {
|
||||
|
|
Loading…
Add table
Reference in a new issue