def generate_html(md_file, config_file): """ Generates html from Moose flavored markdown. Args: md_file[str]: The *.md file or text to convert. config_file[str]: The *.yml configuration file. """ # Load the YAML configuration file config = MooseDocs.load_config(config_file) # Create the markdown parser extensions, extension_configs = MooseDocs.get_markdown_extensions(config) parser = markdown.Markdown(extensions=extensions, extension_configs=extension_configs) # Read and parse the markdown md, settings = MooseDocs.read_markdown(md_file) return parser.convert(md), settings
def build(self, lock=None): """ Converts the markdown to html. """ # Read the markdown and parse the HTML log.debug('Parsing markdown: {}'.format(self.__md_file)) content, meta = MooseDocs.read_markdown(self.__md_file) self.__html = self.__parser.convert(content) template_args = copy.copy(self.__template_args) template_args['navigation'] = self.__navigation template_args.update(meta) # Create the template object env = jinja2.Environment(loader=jinja2.FileSystemLoader([ os.path.join(MooseDocs.MOOSE_DIR, 'docs', 'templates'), os.path.join(os.getcwd(), 'templates') ])) template = env.get_template(self.__template) # Render the html via template complete = template.render(current=self, **template_args) # Make sure the destination directory exists, if it already does do nothing. If it does not exist try to create # it, but include a try statement because it might get created by another process. destination = self.path() if lock: # Lock is not supplied or needed with build function is called from the liveserver with lock: if not os.path.exists(destination): os.makedirs(destination) else: if not os.path.exists(destination): os.makedirs(destination) # Finalize the html soup = self.finalize(bs4.BeautifulSoup(complete, 'html.parser')) # Write the file with open(self.url(), 'w') as fid: log.debug('Creating {}'.format(self.url())) fid.write(soup.encode('utf-8'))