@Override public void processBody(ParserContext context) { StringBuilder body = new StringBuilder(context.getBody().length()); if (!context.hasHeader()) { for (String line : context.getFileLines()) { body.append(line).append("\n"); } context.setBody(body.toString()); } processAsciiDoc(context); }
private void setModelDefaultsIfNotSetInHeader(ParserContext context) { if (context.getDate() == null) { context.setDate(new Date(context.getFile().lastModified())); } // default status has been set if (context.getConfig().getDefaultStatus() != null && context.getStatus().isEmpty()) { // file hasn't got status so use default context.setDefaultStatus(); } // default type has been set if (context.getConfig().getDefaultType() != null && context.getType().isEmpty()) { // file hasn't got type so use default context.setDefaultType(); } }
public void setDefaultStatus() { getDocumentModel().put(Crawler.Attributes.STATUS, getConfig().getDefaultStatus()); }
Options options = getAsciiDocOptionsAndAttributes(context); final Asciidoctor asciidoctor = getEngine(options); DocumentHeader header = asciidoctor.readDocumentHeader(context.getFile()); Map<String, Object> documentModel = context.getDocumentModel(); if (header.getDocumentTitle() != null) { documentModel.put("title", header.getDocumentTitle().getCombined()); String dateFormat = context.getConfig().getDateFormat(); DateFormat df = new SimpleDateFormat(dateFormat); try { Date date = df.parse((String) value); context.setDate(date); } catch (ParseException e) { LOGGER.error("Unable to parse revdate. Expected {}", dateFormat, e); context.setTags(((String) value).split(",")); } else { LOGGER.error("Wrong value of 'jbake-tags'. Expected a String got '{}'", getValueClassName(value));
ParserContext context = new ParserContext( file, fileContents, sanitizeTags(context); if (context.getType().isEmpty() || context.getStatus().isEmpty()) { return context.getDocumentModel();
private void sanitizeTags(ParserContext context) { if (context.getTags() != null) { String[] tags = (String[]) context.getTags(); for (int i = 0; i < tags.length; i++) { tags[i] = sanitizeValue(tags[i]); if (context.getConfig().getSanitizeTag()) { tags[i] = tags[i].replace(" ", "-"); } } context.setTags(tags); } }
@Override public void processBody(final ParserContext context) { List<String> mdExts = context.getConfig().getMarkdownExtensions(); int extensions = Extensions.NONE; for (String ext : mdExts) { if (ext.startsWith("-")) { ext = ext.substring(1); extensions = removeExtension(extensions, extensionFor(ext)); } else { if (ext.startsWith("+")) { ext = ext.substring(1); } extensions = addExtension(extensions, extensionFor(ext)); } } DataHolder options = PegdownOptionsAdapter.flexmarkOptions(extensions); Parser parser = Parser.builder(options).build(); HtmlRenderer renderer = HtmlRenderer.builder(options).build(); Document document = parser.parse(context.getBody()); context.setBody(renderer.render(document)); }
public void setTags(String[] tags) { getDocumentModel().put(Crawler.Attributes.TAGS, tags); } }
/** * Process the header of the file. * * @param context the parser context */ private void processDefaultHeader(ParserContext context) { for (String line : context.getFileLines()) { if (hasHeaderSeparator(line)) { break; } processHeaderLine(line, context.getDocumentModel()); } }
@Override public void processHeader(final ParserContext context) { Map<String, Object> contents = context.getDocumentModel(); contents.put(Attributes.TYPE, "post"); contents.put(Attributes.STATUS, "published"); contents.put(Attributes.TITLE, "Rendering engine missing"); contents.put(Attributes.DATE, new Date()); contents.put(Attributes.TAGS, new String[0]); contents.put(Attributes.ID, context.getFile().getName()); }
/** * Process the body of the file. * * @param context the parser context */ private void processDefaultBody(ParserContext context) { StringBuilder body = new StringBuilder(); boolean inBody = false; for (String line : context.getFileLines()) { if (inBody) { body.append(line).append("\n"); } if (line.equals(configuration.getHeaderSeparator())) { inBody = true; } } if (body.length() == 0) { for (String line : context.getFileLines()) { body.append(line).append("\n"); } } context.setBody(body.toString()); } }
private Options getAsciiDocOptionsAndAttributes(ParserContext context) { JBakeConfiguration config = context.getConfig(); List<String> asciidoctorAttributes = config.getAsciidoctorAttributes(); final AttributesBuilder attributes = attributes(asciidoctorAttributes.toArray(new String[asciidoctorAttributes.size()])); if (config.getExportAsciidoctorAttributes()) { final String prefix = config.getAttributesExportPrefixForAsciidoctor(); for (final Iterator<String> it = config.getKeys(); it.hasNext(); ) { final String key = it.next(); if (!key.startsWith("asciidoctor")) { attributes.attribute(prefix + key.replace(".", "_"), config.get(key)); } } } final List<String> optionsSubset = config.getAsciidoctorOptionKeys(); final Options options = options().attributes(attributes.get()).get(); for (final String optionKey : optionsSubset) { Object optionValue = config.getAsciidoctorOption(optionKey); if (optionKey.equals(Options.TEMPLATE_DIRS)) { List<String> dirs = getAsList(optionValue); if (!dirs.isEmpty()) { options.setTemplateDirs(String.valueOf(dirs)); } } else { options.setOption(optionKey, optionValue); } } options.setBaseDir(context.getFile().getParentFile().getAbsolutePath()); options.setSafe(UNSAFE); return options; }
Options options = getAsciiDocOptionsAndAttributes(context); final Asciidoctor asciidoctor = getEngine(options); DocumentHeader header = asciidoctor.readDocumentHeader(context.getFile()); Map<String, Object> documentModel = context.getDocumentModel(); if (header.getDocumentTitle() != null) { documentModel.put("title", header.getDocumentTitle().getCombined()); String dateFormat = context.getConfig().getDateFormat(); DateFormat df = new SimpleDateFormat(dateFormat); try { Date date = df.parse((String) value); context.setDate(date); } catch (ParseException e) { LOGGER.error("Unable to parse revdate. Expected {}", dateFormat, e); context.setTags(((String) value).split(",")); } else { LOGGER.error("Wrong value of 'jbake-tags'. Expected a String got '{}'", getValueClassName(value));
ParserContext context = new ParserContext( file, fileContents, sanitizeTags(context); if (context.getType().isEmpty() || context.getStatus().isEmpty()) { return context.getDocumentModel();
private void sanitizeTags(ParserContext context) { if (context.getTags() != null) { String[] tags = (String[]) context.getTags(); for (int i = 0; i < tags.length; i++) { tags[i] = sanitizeValue(tags[i]); if (context.getConfig().getSanitizeTag()) { tags[i] = tags[i].replace(" ", "-"); } } context.setTags(tags); } }
@Override public void processBody(final ParserContext context) { List<String> mdExts = context.getConfig().getMarkdownExtensions(); int extensions = Extensions.NONE; for (String ext : mdExts) { if (ext.startsWith("-")) { ext = ext.substring(1); extensions = removeExtension(extensions, extensionFor(ext)); } else { if (ext.startsWith("+")) { ext = ext.substring(1); } extensions = addExtension(extensions, extensionFor(ext)); } } DataHolder options = PegdownOptionsAdapter.flexmarkOptions(extensions); Parser parser = Parser.builder(options).build(); HtmlRenderer renderer = HtmlRenderer.builder(options).build(); Document document = parser.parse(context.getBody()); context.setBody(renderer.render(document)); }
public String getStatus() { if (getDocumentModel().containsKey(Crawler.Attributes.STATUS)) { return getDocumentModel().get(Crawler.Attributes.STATUS).toString(); } return ""; }
/** * Process the header of the file. * * @param context the parser context */ private void processDefaultHeader(ParserContext context) { for (String line : context.getFileLines()) { if (hasHeaderSeparator(line)) { break; } processHeaderLine(line, context.getDocumentModel()); } }