ogom / sublimetext-markdown-slideshow

Sublime Text 2/3 plugin for markdown slideshow
http://ogom.github.com/sublimetext-markdown-slideshow
93 stars 18 forks source link

Adding new theme does not work #10

Closed yoonghm closed 1 year ago

yoonghm commented 9 years ago

I copied 'io2012' directory into 'mytheme' and updated user's setting for Markdown Slideshow to 'mytheme'.

I made the following changes later to 'io2012' theme

Is there a more flexible way?

ogom commented 9 years ago

Download theme from github.

$ cd /opt
$ git clone https://github.com/ogom/mcider-themes.git mcider/themes

And, please set the package settings.

{
  "themes": "/opt/mcider/themes",
  "theme" : "io2012"
}
wdawson4 commented 9 years ago

The reason it did not work was because the get slide function calls _get_slide_none for all themes that are not io2011 or io2012. The _get_slide_none function generates html that is not compatible with the io2011 or io2012 themes. I fixed this in my branch. See My Pull Request #12...

Issue below:

    def _get_slide(self, theme=None, theme_processor=None, contents=None, extensions=[]):
        html = None
        if theme_processor == 'io2011':
            html = self._get_slide_io2011(contents, extensions)
        elif theme_processor == 'io2012':
            html = self._get_slide_io2012(contents, extensions)
        else:
            html = self._get_slide_none(contents, extensions)
        return html

    def _get_slide_none(self, contents=None, extensions=[]):
        """ none style """
        md = Markdown(extensions=extensions)

        # from pages to slides
        pages = md.convert(contents) + '\n'
        slides = pages.split('<hr />\n')

        # from slides to html
        html = '\n'
        for slide in slides:
            html += '<article>\n'
            html += slide
            html += '</article>\n\n'
        return html

    def _get_slide_io2012(self, contents=None, extensions=[]):
        """ io-2012 style """
        md = Markdown(extensions=extensions)
        splits = [
            {'horizon': '----', 'style': 'none'},
            {'horizon': '____', 'style': 'smaller'},
            {'horizon': '****', 'style': 'fill'}
        ]

        styles = []
        for split in splits:
            styles.append(split['style'])
            horizon = '\n' + split['horizon'] + '\n'
            contents = contents.replace(horizon, '\n---\n' + split['style'] + '\n')

        pages = contents.split('\n---\n')

        # from pages to slides
        slides = []
        for page in pages:
            sections = page.split('\n\n', 2)
            slide = {}
            if not sections[0] in styles:
                if len(sections) > 2:
                    sections[1] += '\n\n' + sections[2]
                sections.insert(0, 'none')
            slide['style'] = sections[0]
            if len(sections) > 1:
                slide['hgroup'] = sections[1]
            if len(sections) > 2:
                slide['article'] = sections[2]
            slides.append(slide)

        # from slides to html
        html = '\n'
        for slide in slides:
            html += '<slide>\n'
            if 'hgroup' in slide:
                html += '<hgroup>\n'
                html += md.convert(slide['hgroup']) + '\n'
                html += '</hgroup>\n'
            if 'article' in slide:
                html += '<article class="' + slide['style'] + '">\n'
                html += md.convert(slide['article']) + '\n'
                html += '</article>\n'
            html += '</slide>\n\n'

        # from comment out to presener note
        html = html.replace('\n<!--\n', '\n<aside class="note">\n')
        html = html.replace('\n-->\n', '\n</aside>\n')

        return html

    def _get_slide_io2011(self, contents=None, extensions=[]):
        """ io-2011 style """
        md = Markdown(extensions=extensions)
        splits = [
            {'horizon': '----', 'style': 'none'},
            {'horizon': '____', 'style': 'smaller'},
            {'horizon': '****', 'style': 'fill'}
        ]

        styles = []
        for split in splits:
            styles.append(split['style'])
            horizon = '\n' + split['horizon'] + '\n'
            contents = contents.replace(horizon, '\n---\n' + split['style'] + '\n')

        pages = contents.split('\n---\n')

        # from pages to slides
        slides = []
        for page in pages:
            sections = page.split('\n\n', 1)
            slide = {}
            if not sections[0] in styles:
                if len(sections) > 1:
                    sections[0] += '\n\n' + sections[1]
                sections.insert(0, 'none')
            slide['style'] = sections[0]
            if len(sections) > 1:
                slide['article'] = sections[1]
            slides.append(slide)

        # from slides to html
        html = '\n'
        for slide in slides:
            if 'article' in slide:
                html += '<article class="' + slide['style'] + '">\n'
                html += md.convert(slide['article']) + '\n'
                html += '</article>\n\n'
        return html