Skip to content
Merged
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
11 changes: 7 additions & 4 deletions src/markdown-document.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import * as winston from "winston";

import { default as optionsService, IOptions } from "./services/options-service";
import markdownService from "./services/markdown-service";
import { MarkdownService } from "./services/markdown-service";
import layoutService from "./services/layout-service";
import { default as fileService, TempPath } from "./services/file-service";
import pdfService from "./services/pdf-service";
import { default as metadataService, IPdfMetadata } from "./services/metadata-service";

export class MarkdownDocument {
private service: MarkdownService;

constructor(private options: IOptions) {
this.service = new MarkdownService(options.useHtml);
}

public async createPdfAsync() {
let timer = winston.startTimer();
await optionsService.consolidateAsync(this.options);
Expand All @@ -21,8 +24,8 @@ export class MarkdownDocument {
timer.done('Checked preconditions');

timer = winston.startTimer();
const markdownAsHtml = await markdownService.renderFileAsync(this.options.documentPath);
const markdownMeta = markdownService.getMetadata();
const markdownAsHtml = await this.service.renderFileAsync(this.options.documentPath);
const markdownMeta = this.service.getMetadata();
timer.done('Render markdown to html finished');

timer = winston.startTimer();
Expand Down
9 changes: 5 additions & 4 deletions src/services/markdown-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import fileService from "./file-service";
export class MarkdownService {
private readonly md: IRemarkable;

constructor() {
this.md = this.createRemarkableInstance();
constructor(useHtml: boolean) {
this.md = this.createRemarkableInstance(useHtml);
}

public async renderFileAsync(path: PathLike) {
Expand All @@ -30,8 +30,9 @@ export class MarkdownService {
return this.md.meta;
}

private createRemarkableInstance() {
private createRemarkableInstance(useHtml: boolean) {
const md = new Remarkable({
html: useHtml,
xhtmlOut: true,
highlight: this.highlight
});
Expand Down Expand Up @@ -59,4 +60,4 @@ export class MarkdownService {
}
}

export default new MarkdownService();
export default new MarkdownService(false);
3 changes: 3 additions & 0 deletions src/services/options-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface IOptions {

document?: IDocumentInformation;
pdf?: IPdfOptions;
useHtml?: boolean;
}

export interface IPdfOptions {
Expand Down Expand Up @@ -118,6 +119,7 @@ export class OptionsService {
this.applyFallbackOptions(options, <IOptions>{
language: 'en',
writeMetadata: true,
useHtml: false,

pdf: {
wkhtmltopdfPath: require('wkhtmltopdf-installer').path,
Expand All @@ -139,6 +141,7 @@ export class OptionsService {

private applyFallbackOptions(options: IOptions, fallback: IOptions) {
options.language = options.language || fallback.language;
options.useHtml = options.useHtml || fallback.useHtml;
options.writeMetadata = options.writeMetadata == null ? fallback.writeMetadata : options.writeMetadata;

options.pdf = options.pdf || { };
Expand Down