mirror of
https://github.com/lise-henry/crowbook
synced 2024-11-18 00:13:55 +01:00
Book now supports multiline strings
This commit is contained in:
parent
93b7f828d4
commit
770822ac43
6
Bugs.md
6
Bugs.md
@ -1,11 +1,9 @@
|
||||
Bugs
|
||||
====
|
||||
|
||||
* html: no table of contents
|
||||
* epub: no way to embed custom files to epub
|
||||
* latex: no support images
|
||||
* epub: toc.ncx currently only displays chapters (first level headers)
|
||||
* latex: no support for images
|
||||
* odt: no support for... a lot of stuff, actually
|
||||
* config: can't handle multiline string, which is a problem for fields
|
||||
like "desscription"
|
||||
* config: can't parse specified numbers for negative chapter (is it
|
||||
really a bug?)
|
||||
|
@ -3,6 +3,8 @@ ChangeLog
|
||||
|
||||
0.2.0 (unreleased)
|
||||
------------------
|
||||
* Added support for multiline strings in `.book` files, with either
|
||||
'|' (preserving line returns) or '>' (transforming line returns in spaces)
|
||||
* New option `display_toc` allows to display the table of contents
|
||||
(whose name, at least for HTML, is specified by `toc_name`) in HTML
|
||||
and PDF documents.
|
||||
|
@ -1,5 +1,7 @@
|
||||
# Metadata
|
||||
author: Élisabeth Henry
|
||||
author: >
|
||||
Élisabeth
|
||||
Henry
|
||||
title: Crowbook
|
||||
description: More like some kind of manual really
|
||||
lang: en
|
||||
|
@ -6,7 +6,7 @@ is all you'll have to add (assuming you'll already have the book in
|
||||
Markdown files; if you don't, you'll also have to write a book first,
|
||||
but that's besides the scope of this document).
|
||||
|
||||
The format is not very complicated. This is an example of it:
|
||||
The format is not very complicated, and it looks a bit like YAML. This is an example of it:
|
||||
|
||||
```
|
||||
# metadata
|
||||
@ -126,6 +126,33 @@ title: My title
|
||||
If you *do* use quotes, Crowbook will actually put those quotes in the
|
||||
string, so basically don't do that.
|
||||
|
||||
It is possible to use multiline strings with either `>` or `|`, and
|
||||
then indenting the lines that are part of the string:
|
||||
|
||||
```
|
||||
title: >
|
||||
A
|
||||
long
|
||||
title
|
||||
author: Joan Doe
|
||||
```
|
||||
|
||||
will set `title` to `"A long title"`, whereas
|
||||
|
||||
```
|
||||
title: >
|
||||
A
|
||||
long
|
||||
title
|
||||
author: Joan Doe
|
||||
```
|
||||
|
||||
will set `title` to `"A\nlong\ntitle\n"` (replicating line returns).
|
||||
|
||||
This feature is useful for options like `description` who may take a
|
||||
long string.
|
||||
|
||||
|
||||
### Options summary ###
|
||||
|
||||
### Metadata ###
|
||||
|
@ -361,7 +361,31 @@ impl Book {
|
||||
Ok(words[0])
|
||||
}
|
||||
|
||||
let mut multiline = false;
|
||||
let mut join_new_line = false;
|
||||
let mut prev_key = String::new();
|
||||
let mut prev_value = String::new();
|
||||
|
||||
for line in s.lines() {
|
||||
// If we are multiline mode, we already have a key and a (building) value
|
||||
if multiline {
|
||||
if line.starts_with(' ') {
|
||||
// multiline continues
|
||||
prev_value.push_str(line.trim());
|
||||
if join_new_line {
|
||||
prev_value.push_str("\n");
|
||||
} else {
|
||||
prev_value.push_str(" ");
|
||||
}
|
||||
continue;
|
||||
} else {
|
||||
// end multiline
|
||||
try!(self.set_option(&prev_key, &prev_value));
|
||||
multiline = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let line = line.trim();
|
||||
if line.is_empty() || line.starts_with('#') {
|
||||
continue;
|
||||
@ -396,9 +420,20 @@ impl Book {
|
||||
}
|
||||
let key = parts[0].trim();
|
||||
let value = parts[1].trim();
|
||||
try!(self.set_option(key, value));
|
||||
match value {
|
||||
">" | "|" => { // multiline string
|
||||
multiline = true;
|
||||
join_new_line = value == "|";
|
||||
prev_key = key.to_owned();
|
||||
prev_value = String::new();
|
||||
},
|
||||
_ => try!(self.set_option(key, value)),
|
||||
}
|
||||
}
|
||||
}
|
||||
if multiline {
|
||||
try!(self.set_option(&prev_key, &prev_value));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -133,9 +133,9 @@ table.notes td {
|
||||
font-variant: small-caps;
|
||||
}
|
||||
|
||||
li {
|
||||
ul li {
|
||||
list-style-type: none;
|
||||
}
|
||||
li:before {
|
||||
ul li:before {
|
||||
content: "– ";
|
||||
}
|
@ -16,10 +16,19 @@ nav {
|
||||
margin-right: 10%;
|
||||
transition: margin-left 1s;
|
||||
}
|
||||
|
||||
#toc ul, #toc li, #nav ul, #nav li {
|
||||
list-style-type: none;
|
||||
}
|
||||
|
||||
#toc li:before {
|
||||
content: none;
|
||||
}
|
||||
|
||||
#nav li:before {
|
||||
content: none;
|
||||
}
|
||||
|
||||
|
||||
#nav ul {
|
||||
margin-left: 0;
|
||||
padding-right: 1em;
|
||||
|
Loading…
Reference in New Issue
Block a user