Skip to content
Closed
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
9 changes: 9 additions & 0 deletions book-example/src/format/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,15 @@ The following configuration options are available:
an icon link will be output in the menu bar of the book.
- **git-repository-icon:** The FontAwesome icon class to use for the git
repository link. Defaults to `fa-github`.
- **git-repository-edit-url-template:** Git repository file edit url
template, when provided shows an "Suggest an edit" button for
directly jumping to editing the currently viewed page in the git
repository. For e.g. GitHub projects set this to
`https://github.com/<owner>/<repo>/edit/master/{path}` or for
Bitbucket projects set it to
`https://bitbucket.org/<owner>/<repo>/src/master/{path}?mode=edit`
where {path} will be replaced with the full path of the file in the
repository.

Available configuration options for the `[output.html.fold]` table:

Expand Down
5 changes: 5 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,11 @@ pub struct HtmlConfig {
/// FontAwesome icon class to use for the Git repository link.
/// Defaults to `fa-github` if `None`.
pub git_repository_icon: Option<String>,
/// Git repository file edit url template, when set shows an
/// "Suggest an edit" button for directly jumping to editing the
/// currently viewed page in the git repository. Contains {path}
/// that is replaced with chapter source file path
pub git_repository_edit_url_template: Option<String>,
/// This is used as a bit of a workaround for the `mdbook serve` command.
/// Basically, because you set the websocket port from the command line, the
/// `mdbook serve` command needs a way to let the HTML renderer know where
Expand Down
9 changes: 9 additions & 0 deletions src/renderer/html_handlebars/hbs_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ impl HtmlHandlebars {
bail!(ErrorKind::ReservedFilenameError(ch.path.clone()));
};

if let Some(ref git_repository_edit_url_template) =
ctx.html_config.git_repository_edit_url_template
{
let full_path = "src/".to_owned() + path;
let edit_url = git_repository_edit_url_template.replace("{path}", &full_path);
ctx.data
.insert("git_repository_edit_url".to_owned(), json!(edit_url));
}

// Non-lexical lifetimes needed :'(
let title: String;
{
Expand Down
5 changes: 5 additions & 0 deletions src/theme/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@
<i id="git-repository-button" class="fa {{git_repository_icon}}"></i>
</a>
{{/if}}
{{#if git_repository_edit_url}}
<a href="{{git_repository_edit_url}}" title="Suggest an edit" aria-label="Suggest an edit">
<i id="git-edit-button" class="fa fa-edit"></i>
</a>
{{/if}}
</div>
</div>
</div>
Expand Down