Skip to content
Open
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion lib/Gitprep/API.pm
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@ sub add_issue_message {
# file the markdown file path within repository
# tree the markdown file's directory within repository
# site_url Base url to convert into an absolute url (Mojo::URL).
# toc Generate table of content, not page.
#
# If not defined, tree is computed from file.
# Wiki links are translated only if the repository is a wiki.
Expand Down Expand Up @@ -701,7 +702,9 @@ sub markdown {
}

# Convert to HTML.
my $html_text = Text::Markdown::Hoedown::markdown($markdown_text,
my $proc = \&Text::Markdown::Hoedown::markdown;
$proc = \&Text::Markdown::Hoedown::markdown_toc if $params{toc};
my $html_text = $proc->($markdown_text,
extensions => HOEDOWN_EXT_FENCED_CODE|HOEDOWN_EXT_TABLES|HOEDOWN_EXT_NO_INTRA_EMPHASIS
);

Expand Down
27 changes: 10 additions & 17 deletions public/css/common.css
Original file line number Diff line number Diff line change
Expand Up @@ -292,31 +292,24 @@ a.wiki-btn-history:hover {

}

.wiki-list-pages-box {
background-color: #fcfcfc;
border-radius: 3px;
border: 1px solid #e6e9e6;
padding: 9px 6px;
font-size: 14px;
line-height: 17px;
font-weight:bold;
color:#004763;
text-align:center;
.wiki-list-pages {
padding:15px 12px;
font-size:16px;
}

.wiki-list-pages-box a {
text-decoration:underline;
.wiki-list-pages summary {
font-weight: bold;
}

.wiki-list-pages {
padding:15px 12px;
font-size:15px;
.wiki-list-pages details *:not(summary) a,
.wiki-list-pages details *:not(summary) a:visited {
color: #000;
}

.wiki-list-pages li {
list-style-type: disc;
list-style-type: none;
margin-left:20px;
font-size:16px;
font-size:15px;
margin-bottom:3px;
}

Expand Down
2 changes: 0 additions & 2 deletions public/js/jquery-3.7.1.min.js

This file was deleted.

2 changes: 2 additions & 0 deletions public/js/jquery-4.0.0.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion templates/layouts/common.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
% for my $stylesheet (@$stylesheets) {
%= stylesheet $stylesheet;
% }
%= javascript '/js/jquery-3.7.1.min.js';
%= javascript '/js/jquery-4.0.0.min.js';
%= javascript '/js/bootstrap.min.js';
%= javascript '/js/gitprep.js';

Expand Down
53 changes: 47 additions & 6 deletions templates/wiki.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
my $title_to_delete = param('title-to-delete');
eval { $title_to_delete = Encode::decode('UTF-8', $title_to_delete) };
my $success = 0;
if ($api->wiki_safe_title($title_to_delete) eq $title_to_delete) {
if ($canadmin &&
$api->wiki_safe_title($title_to_delete) eq $title_to_delete) {
$api->delete_wiki_page($wiki_rep_info, $title_to_delete);
flash(message => "$title_to_delete deleted");
$success = 1;
Expand All @@ -66,6 +67,25 @@
$self->render(json => {success => $success});
return;
}
elsif ($op eq 'ajax-toc') {
my $toc = '';
if ($api->wiki_page_exists($wiki_rep_info, $title)) {
$content = $api->get_wiki_page_content($wiki_rep_info, $title);
if (defined $content) {
# Get page table of contents.
$toc = $api->markdown(
$content,
$wiki_rep_info,
rev => 'master',
toc => 1
);
my $url = url_for($wiki_rep_info->url($title));
$toc =~ s@\bhref="#@href="$url#@g;
}
}
$self->render(json => $toc);
return;
}
}
# Form request
else {
Expand Down Expand Up @@ -278,6 +298,25 @@
});
}
});

// Open page toc details.
$('.wiki-list-pages details[wptitle]').on('toggle', function () {
var self = $(this);
if (self.attr('open') != undefined && !self.attr('filled')) {
self.attr('filled', '1');
var rep_url = '<%= url_for($wiki_rep_info->url) %>';
$.post({
url: rep_url + '/' + self.attr('wptitle'),
data: {
op: 'ajax-toc'
},
dataType: 'json',
success: function (result) {
self.append(result);
}
});
}
});
});
% end

Expand Down Expand Up @@ -467,13 +506,15 @@
Pages
</div>
<div class="wiki-frame">
<ul class="wiki-list-pages">
<div class="wiki-list-pages">
% for my $page (@$pages) {
<li>
<a href="<%= url_for($wiki_rep_info->url($page)) %>"><%= $page %></a>
</li>
<details wptitle="<%= $page %>">
<summary>
<a href="<%= url_for($wiki_rep_info->url($page)) %>"><%= $page %></a>
</summary>
</details>
% }
</ul>
</div>
</div>
</div>
% }
Expand Down