added mardown support into the code folder view

This commit is contained in:
hyung-hwan 2016-01-14 07:51:27 +00:00
parent a0ed60c6b6
commit 9c53e9f759
9 changed files with 2615 additions and 36 deletions

View File

@ -255,7 +255,7 @@ cloc_command_path = "@CFGDIR@/cloc.pl"
; The first file found is shown. You can specify multiple file name
; separated by a comma.
;------------------------------------------------------------------------------
code_folder_readme = "README.wiki,README.txt,README"
code_folder_readme = "README.wiki,README.txt,README.wc,README.md,README"
;------------------------------------------------------------------------------
; Email address to use when sending notification emails

View File

@ -11,6 +11,7 @@
<link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/font-awesome.min.css')?>" />
<script type="text/javascript" src="<?php print base_url_make('/js/creole.js')?>"></script>
<script type="text/javascript" src="<?php print base_url_make('/js/showdown.js')?>"></script>
<script type="text/javascript" src="<?php print base_url_make('/js/prettify/prettify.js')?>"></script>
<script type="text/javascript" src="<?php print base_url_make('/js/prettify/lang-css.js')?>"></script>
@ -197,19 +198,56 @@ function show_loc_by_file_graph (response)
$("#code_folder_loc_by_file_spin" ).removeClass ("fa-cog fa-spin");
}
function showdown_render_wiki (inputid, outputid)
{
var sd = new showdown.Converter ({
omitExtraWLInCodeBlocks: false,
noHeaderId: false,
prefixHeaderId: false,
parseImgDimensions: true,
headerLevelStarT: 1,
simplifiedAutoLink: false,
literalMidWordUnderscores: false,
strikethrough: true,
tables: true,
tablesHeaderId: false,
ghCodeBlocks: true,
tasklists: true
});
function decodeEntities(str)
{
return str.replace(/&amp;/g, '&').
replace(/&lt;/g, '<').
replace(/&gt;/g, '>').
replace(/&quot;/g, '"');
}
var input = document.getElementById(inputid);
var output = document.getElementById(outputid);
output.innerHTML = sd.makeHtml(decodeEntities(input.innerHTML));
}
function render_readme()
{
<?php
// if the readme file name ends with '.wiki', perform wiki formatting and pretty printing
if (strlen($readme_text) > 0 && substr_compare($readme_file, '.wiki', -5) === 0):
if (strlen($readme_text) > 0 && (substr_compare($readme_file, '.wiki', -5) === 0 ||
substr_compare($readme_file, '.wc', -3) === 0)):
?>
creole_render_wiki (
"code_folder_result_readme_text",
"code_folder_result_readme",
"code_folder_readme_text",
"code_folder_readme",
codepot_merge_path("<?php print site_url(); ?>", "/wiki/show/<?php print $project->id?>/"),
codepot_merge_path("<?php print site_url(); ?>", "/wiki/attachment0/<?php print $project->id?>/")
);
prettyPrint();
<?php
// if the readme file name ends with '.wiki', perform markdown formatting
elseif (strlen($readme_text) > 0 && substr_compare($readme_file, '.md', -3) === 0):
?>
showdown_render_wiki ("code_folder_readme_text", "code_folder_readme");
<?php endif; ?>
}
@ -1106,25 +1144,24 @@ $this->load->view (
}
}
print '</table>';
}
?>
</div> <!-- code_folder_result -->
<?php
if (strlen($readme_text) > 0)
{
print '<div id="code_folder_result_readme">';
print '<div id="code_folder_readme">';
// the pre division is gone when rendered as a wiki text.
// so is the pre-wrapped class. so let me put the class
// regardless of the text type.
print '<pre id="code_folder_result_readme_text" class="pre-wrapped">';
print "\n";
print '<pre id="code_folder_readme_text" class="pre-wrapped">';
print htmlspecialchars($readme_text);
print "\n";
print '</pre>';
print '</div>';
}
}
?>
</div> <!-- code_folder_result -->
<?php if (isset($login['id']) && $login['id'] != ''): ?>
<div id="code_folder_mainarea_new_form_div">

View File

@ -52,7 +52,6 @@ function show_alert (outputMsg, titleMsg)
});
}
function resize_editor()
{
var editor = $("#wiki_edit_text_editor");
@ -404,6 +403,10 @@ $(function () {
});
$(window).resize(resize_editor);
// intentional double resizing as it seemed better handling
// quirkiness of medium editor's toolbar
resize_editor ();
resize_editor ();
});
</script>

View File

@ -96,7 +96,7 @@ $this->load->view (
<div class="actions">
<?php if (isset($login['id']) && $login['id'] != ''): ?>
<a id="wiki_home_new_h_button" href='#'><?php print $this->lang->line('New')?> [H]</a>
<a id="wiki_home_new_c_button" href='#'><?php print $this->lang->line('New')?> [C]</a>
<a id="wiki_home_new_c_button" href='#'><?php print $this->lang->line('New')?> [WC]</a>
<?php endif; ?>
<!-- <a id="wiki_home_search_button" href='#'><?php print $this->lang->line('Search')?></a> -->
</div>

View File

@ -135,20 +135,6 @@
background-color: #F0FAF0;
}
#code_folder_result_readme {
padding: 0.2em 0.2em 0.2em 0.2em;
}
#code_folder_result_readme_text {
white-space: pre-wrap;
padding: 0.3em;
line-height: 1.2em;
background-color: #F8F8FA;
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
border-radius: 3px;
}
#code_folder_result_loc_by_file_graph {
overflow: auto;
@ -182,6 +168,40 @@
stroke-width: 1.5px;
}
#code_folder_readme {
margin: 0.2em 0 0 0;
padding: 0.3em 0.3em 0.3em 0.3em;
white-space: normal;
line-height: 1.2em;
background-color: #FAFAFA;
border: none;
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
border-radius: 3px;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
#code_folder_readme h1 {
border-bottom: 1px solid #DDD;
font-weight: bold;
line-height: 1.4em;
}
#code_folder_readme pre {
white-space: pre-wrap !important;
word-wrap: break-word !important;
background-color: #EEEEEE;
border: 1px solid #DFDFDF;
}
#code_folder_readme pre code {
white-space: pre-wrap !important;
word-wrap: break-word !important;
margin: 0 !important;
padding: 0 !important;
}
/*-----------------------------------------------
* project source edit view
*-----------------------------------------------*/

View File

@ -145,13 +145,20 @@
#wiki_edit_text_area,
#wiki_edit_text_editor {
margin: 0 !important;
padding: 0 !important;
padding: 0.2em 0.2em 0.2em 0.2em !important;
width: 100% !important;
border: none !important;
background-color: #F9F9F9 !important;
overflow-y: auto !important;
overflow-x: visible !important;
outline: none !important;
border: #C0C0C0 solid 1px !important;
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
border-radius: 3px;
-moz-box-sizing: border-box !important;
-webkit-box-sizing: border-box !important;
box-sizing: border-box !important;
}
#wiki_edit_text_editor pre {

View File

@ -26,6 +26,7 @@ www_DATA = \
jqueryui-editable.min.js \
medium-editor.min.js \
medium-editor-tables.min.js \
showdown.js \
d3.min.js \
CodeFlower.js

View File

@ -179,6 +179,7 @@ www_DATA = \
jqueryui-editable.min.js \
medium-editor.min.js \
medium-editor-tables.min.js \
showdown.js \
d3.min.js \
CodeFlower.js

2510
codepot/src/js/showdown.js Normal file

File diff suppressed because it is too large Load Diff