Merge pull request #10 from RealOrangeOne/styling

Styling
This commit is contained in:
Jake Howard 2017-05-11 13:43:06 +01:00 committed by GitHub
commit e450824d9b
9 changed files with 55 additions and 8 deletions

View file

@ -12,3 +12,14 @@ Images take the same syntax as with standard markdown:
Referencing files inside your project directory can be done with a path relative to the project directory. You can use images direct from online, however you'll need to be connected to the internet when generating.
The title for the image is also used as the caption, and is displayed directly under the images.
### Linking
You can link to other parts of your document by their titles, in the same way linking to ids works on the web.
For example, if you had a title _Some Title_, then you can link to it like:
[Click Here!](#some-title)
__Note__: The header size doesnt matter. You link to an h4 tag the same as linking to an h1.

View file

@ -1,4 +1,5 @@
$image-spacing: 30px;
$font-size-base: 12px;
body.cover {
@ -6,7 +7,7 @@ body.cover {
text-align: center;
& h1 {
padding-top: 400px;
padding-top: 300px;
font-size: 48px;
}
@ -22,17 +23,38 @@ body.cover {
body.content {
line-height: 1.5;
font-size: 12px;
font-size: $font-size-base;
img {
margin-top: $image-spacing;
width: 100%;
page-break-after: avoid;
}
p.caption {
margin: 1px 5px $image-spacing;
padding: 0;
font-style: italic;
page-break-before: avoid;
}
.references-title {
page-break-before: always;
}
h1, h2, h3, h4, h5, h6 {
page-break-after: avoid;
}
}
body.footer, body.header {
font-size: $font-size-base;
table {
width: 100%;
td {
text-align: center;
}
}
}

View file

@ -4,9 +4,9 @@
<link rel="stylesheet" href="../static/style.css" />
</head>
<body class="footer">
<table style="width: 100%;">
<table>
<tr>
<td style="text-align: center">
<td>
Page <span class="page"></span> of <span class="topage"></span>
</td>
</tr>

View file

@ -6,12 +6,14 @@ from md_pdf.build.pdf import export_pdf
from md_pdf.build.template import parse_template
import os
import logging
import time
logger = logging.getLogger(__file__)
def build(config):
logger.debug("Starting Build...")
start_time = time.time()
data = read_files(os.path.abspath(config['input']))
doc = build_document(data, config.get('bibliography'), config.get('context'))
parsed_template = parse_template(doc, config)
@ -21,3 +23,4 @@ def build(config):
render_cover(config)
render_css()
export_pdf(parsed_template, config)
logger.info('Output completed in {:.2f} seconds.'.format(time.time() - start_time))

View file

@ -4,6 +4,7 @@ from md_pdf.build.cover import OUTPUT_COVER_FILE
import os
import logging
logger = logging.getLogger(__file__)
@ -14,8 +15,8 @@ STYLE_FILE = os.path.join(STATIC_DIR, 'style.css')
HEADER_FILE = os.path.join(TEMPLATES_DIR, 'header.html')
FOOTER_FILE = os.path.join(TEMPLATES_DIR, 'footer.html')
PDF_OPTIONS = {
"quiet": "",
"no-pdf-compression": "",
"enable-internal-links": "",
"header-html": HEADER_FILE,
"footer-html": FOOTER_FILE,
@ -27,6 +28,8 @@ PDF_OPTIONS = {
def export_pdf(content, config):
if logger.getEffectiveLevel() > logging.DEBUG:
PDF_OPTIONS['quiet'] = ""
PDF_OPTIONS['title'] = config.get('title', 'Output')
PDF_OPTIONS['replace'] = [(key, str(value)) for key, value in config['context'].items()]

View file

@ -12,6 +12,7 @@ def fix_references_title(content, config):
reference_element = soup.find('div', class_='references')
if reference_element is not None:
title = soup.new_tag('h1')
title['class'] = 'references-title'
title.string = "References"
reference_element.insert_before(title)
return soup.prettify()
@ -20,8 +21,10 @@ def fix_references_title(content, config):
def add_base_tag(doc, config):
logger.debug("Adding Base Tag...")
soup = BeautifulSoup(doc, 'html.parser')
base_tag = soup.new_tag('base', href=os.path.abspath(config['output_dir']))
soup.head.insert(0, base_tag)
for img in soup.findAll('img'):
abs_path = os.path.abspath(img['src'])
if os.path.isfile(abs_path):
img['src'] = abs_path
return soup.prettify()

View file

@ -3,3 +3,5 @@
_Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam ante purus, scelerisque sed pulvinar eget, suscipit feugiat augue. Cras quis quam ac dui aliquam rhoncus eu id diam. Cras dapibus vel nunc in finibus. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Nulla a lacinia nibh. Aenean finibus mauris et est euismod aliquam. Curabitur dictum nulla quis turpis fringilla vestibulum at eget ligula. Donec et ultricies massa, ut volutpat neque. Praesent elementum ultrices urna at finibus. Nunc risus mi, porta sed eros sit amet, sagittis sollicitudin velit. Nulla a felis in tellus gravida pretium sit amet eget libero. Donec aliquet ac est semper molestie._
__Curabitur arcu velit, faucibus sed condimentum vitae, consectetur a lectus. Fusce a cursus magna. Nam vel posuere erat, in congue purus. Aliquam aliquet eu leo vel cursus. Vestibulum mattis est ac diam finibus, in aliquet erat iaculis. Phasellus est quam, rutrum a tempus non, vehicula vitae tellus. Nam nec leo consectetur, aliquam lorem eget, dignissim arcu. Phasellus vitae convallis urna, ac aliquet purus. Vivamus nisl mauris, volutpat quis pretium non, fringilla non dui. Pellentesque velit justo, pretium a porta nec, varius ac lacus.__
[reference](#test-image)

View file

@ -1,4 +1,4 @@
### Referencing test
- [@nonexistent]

View file

@ -2,3 +2,6 @@
![title](./test-image.png)
![Example remote image](http://image.spreadshirtmedia.com/image-server/v1/designs/11735885,width=178,height=178/TV-Test-Screen.png)