예제 #1
0
    def test_detect_format(self):
        "detect format based on default handlers"

        for filename, Handler in self.TEST_FILES.items():
            with codecs.open(filename, 'r', 'utf-8') as f:
                format = frontmatter.detect_format(f.read(), frontmatter.handlers)
                self.assertIsInstance(format, Handler)
예제 #2
0
    def test_no_handler(self):
        "default to YAMLHandler when no handler is attached"
        post = frontmatter.load('tests/hello-world.markdown')
        del post.handler

        text = frontmatter.dumps(post)
        self.assertIsInstance(
            frontmatter.detect_format(text, frontmatter.handlers), YAMLHandler)
예제 #3
0
    def test_detect_format(self):
        "detect format based on default handlers"

        for filename, Handler in self.TEST_FILES.items():
            with codecs.open(filename, 'r', 'utf-8') as f:
                format = frontmatter.detect_format(f.read(),
                                                   frontmatter.handlers)
                self.assertIsInstance(format, Handler)
예제 #4
0
    def test_no_handler(self):
        "default to YAMLHandler when no handler is attached"
        post = frontmatter.load('tests/hello-world.markdown')
        del post.handler

        text = frontmatter.dumps(post)
        self.assertIsInstance(
            frontmatter.detect_format(text, frontmatter.handlers), 
            YAMLHandler)
예제 #5
0
    def test_detect_format(self):
        "detect format based on default handlers"
        test_files = {
            'tests/hello-world.markdown': YAMLHandler, 
            'tests/hello-json.markdown': JSONHandler,
            'tests/hello-toml.markdown': TOMLHandler
        }

        for fn, Handler in test_files.items():
            with codecs.open(fn, 'r', 'utf-8') as f:
                format = frontmatter.detect_format(f.read(), frontmatter.handlers)
                self.assertIsInstance(format, Handler)
예제 #6
0
    def test_detect_format(self):
        "detect format based on default handlers"
        test_files = {
            'tests/hello-world.markdown': YAMLHandler,
            'tests/hello-json.markdown': JSONHandler,
            'tests/hello-toml.markdown': TOMLHandler
        }

        for fn, Handler in test_files.items():
            with codecs.open(fn, 'r', 'utf-8') as f:
                format = frontmatter.detect_format(f.read(),
                                                   frontmatter.handlers)
                self.assertIsInstance(format, Handler)
예제 #7
0
    def split(self, raw_content, *, encoding="utf-8"):
        raw_content = u(raw_content, encoding).strip()

        # this will only run if a handler hasn't been set higher up
        self.handler = self.handler or detect_format(raw_content, handlers)
        if self.handler is None:
            return None, raw_content, None

        try:
            fm, content = self.handler.split(raw_content)
        except ValueError:
            return None, raw_content, self.handler

        return fm, content, self.handler