Skip to content

Commit

Permalink
feat(hr): add horizontal rule rendering functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
JeelGajera committed Jan 4, 2025
1 parent 0103508 commit 843455e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/renderer/MdTextRender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { RenderOption } from '../types/renderOption';
import { HandlePageBreaks } from '../utils/handlePageBreak';
import {
renderHeading,
renderHR,
renderList,
renderListItem,
renderParagraph,
Expand Down Expand Up @@ -82,6 +83,9 @@ export const MdTextRender = async (
ordered,
);
break;
case MdTokenType.Hr:
y = renderHR(doc, y, options);
break;
case MdTokenType.Raw:
case MdTokenType.Text:
y = renderRawItem(
Expand Down
14 changes: 14 additions & 0 deletions src/renderer/components/hr.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import jsPDF from 'jspdf';
import { RenderOption } from '../../types';
import { getCharHight } from '../../utils/doc-helpers';

const renderHR = (doc: jsPDF, y: number, options: RenderOption) => {
const pageWidth = doc.internal.pageSize.getWidth();
doc.setLineDashPattern([1, 1], 0);
doc.setLineWidth(0.1);
doc.line(options.page.xpading, y, pageWidth - options.page.xpading, y);
doc.setLineWidth(0.1);
doc.setLineDashPattern([], 0);
return y + getCharHight(doc, options);
};
export default renderHR;
1 change: 1 addition & 0 deletions src/renderer/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export { default as renderParagraph } from './paragraph';
export { default as renderList } from './list';
export { default as renderListItem } from './listItem';
export { default as renderRawItem } from './rawItem';
export { default as renderHR } from './hr';

0 comments on commit 843455e

Please sign in to comment.