MCPcopy Create free account
hub / github.com/KDE/okular / convertOpenFile

Method convertOpenFile

generators/markdown/converter.cpp:89–154  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

87}
88
89QTextDocument *Converter::convertOpenFile()
90{
91 int result = fseek(m_markdownFile, 0, SEEK_SET);
92 if (result != 0) {
93 Q_EMIT error(i18n("Failed to open the document"), -1);
94 return nullptr;
95 }
96
97#if defined(MKD_NOLINKS)
98 // on discount 2 MKD_NOLINKS is a define
99 MMIOT *markdownHandle = mkd_in(m_markdownFile, 0);
100
101 int flags = MKD_FENCEDCODE | MKD_GITHUBTAGS | MKD_AUTOLINK | MKD_TOC | MKD_IDANCHOR;
102 if (!m_isFancyPantsEnabled) {
103 flags |= MKD_NOPANTS;
104 }
105 if (!mkd_compile(markdownHandle, flags)) {
106 Q_EMIT error(i18n("Failed to compile the Markdown document."), -1);
107 return nullptr;
108 }
109#else
110 // on discount 3 MKD_NOLINKS is an enum value
111 MMIOT *markdownHandle = mkd_in(m_markdownFile, nullptr);
112
113 mkd_flag_t *flags = mkd_flags();
114 // These flags aren't bitflags, so they can't be | together
115 mkd_set_flag_num(flags, MKD_FENCEDCODE);
116 mkd_set_flag_num(flags, MKD_GITHUBTAGS);
117 mkd_set_flag_num(flags, MKD_AUTOLINK);
118 mkd_set_flag_num(flags, MKD_TOC);
119 mkd_set_flag_num(flags, MKD_IDANCHOR);
120 if (!m_isFancyPantsEnabled) {
121 mkd_set_flag_num(flags, MKD_NOPANTS);
122 }
123 if (!mkd_compile(markdownHandle, flags)) {
124 Q_EMIT error(i18n("Failed to compile the Markdown document."), -1);
125 mkd_free_flags(flags);
126 return nullptr;
127 }
128 mkd_free_flags(flags);
129#endif
130
131 char *htmlDocument;
132 const int size = mkd_document(markdownHandle, &htmlDocument);
133
134 const QString html = detail::fixupHtmlTags(QString::fromUtf8(htmlDocument, size));
135
136 QTextDocument *textDocument = new QTextDocument;
137 textDocument->setPageSize(QSizeF(PAGE_WIDTH, PAGE_HEIGHT));
138 textDocument->setHtml(html);
139 if (generator()) {
140 textDocument->setDefaultFont(generator()->generalSettings()->font());
141 }
142
143 mkd_cleanup(markdownHandle);
144
145 QTextFrameFormat frameFormat;
146 frameFormat.setMargin(PAGE_MARGIN);

Callers

nothing calls this directly

Calls 3

fontMethod · 0.80
generalSettingsMethod · 0.80
setPageSizeMethod · 0.45

Tested by

no test coverage detected