コード例 #1
0
ファイル: test_markdown.py プロジェクト: dendronhq/notesdir
def test_ignore_fenced_code_blocks(fs):
    doc = """#tag1 [link](link1.md)
```foo
#tag2 #tag3
text [link](link1.md)
```
  #tag3 [link](link2.md)

   ```
   [link](link3.md)
   ```"""
    path = '/fakenotes/text.md'
    fs.create_file(path, contents=doc)
    acc = MarkdownAccessor(path)
    info = acc.info()
    assert info.tags == {'tag1', 'tag3'}
    assert info.links == [
        LinkInfo(path, 'link1.md'),
        LinkInfo(path, 'link2.md')
    ]
    acc.edit(ReplaceHrefCmd(path, 'link1.md', 'CHANGED1'))
    acc.edit(ReplaceHrefCmd(path, 'link2.md', 'CHANGED2'))
    acc.edit(ReplaceHrefCmd(path, 'link3.md', 'CHANGED3'))
    acc.edit(DelTagCmd(path, 'tag3'))
    acc.edit(DelTagCmd(path, 'tag2'))
    acc.save()
    assert Path(path).read_text() == """#tag1 [link](CHANGED1)
コード例 #2
0
ファイル: test_html.py プロジェクト: dendronhq/notesdir
def test_change_tags(fs):
    doc = """<html>
    <head>
        <meta name="keywords" content="one, two"/>
    </head>
    <body>
        text
    </body>
</html>"""
    expected = """<html>
    <head>
        <meta name="keywords" content="three, two"/>
    </head>
    <body>
        text
    </body>
</html>"""
    path = Path('/fakenotes/test.html')
    fs.create_file(path, contents=doc)
    acc = HTMLAccessor(str(path))
    acc.edit(AddTagCmd(str(path), 'THREE'))
    acc.edit(DelTagCmd(str(path), 'ONE'))
    assert acc.save()
    assert BeautifulSoup(
        path.read_text(),
        'lxml',
    ) == BeautifulSoup(expected, 'lxml')
コード例 #3
0
def test_remove_hashtag(fs):
    doc = '#Tag1 tag1 #tag1. tag1#tag1 #tag1 #tag2 #tag1'
    # TODO Currently none of the whitespace around a tag is removed when the tag is, which can leave things
    #      pretty ugly. But I'm not sure what the best approach is.
    expected = ' tag1 . tag1#tag1  #tag2 '
    path = '/fakenotes/test.md'
    fs.create_file(path, contents=doc)
    acc = MarkdownAccessor(path)
    assert acc.info().tags == {'tag1', 'tag2'}
    acc.edit(DelTagCmd(path, 'tag1'))
    assert acc.save()
    assert Path(path).read_text() == expected
コード例 #4
0
    def change(self, paths: Set[str], add_tags=Set[str], del_tags=Set[str], title=Optional[str],
               created=Optional[datetime]) -> None:
        """Applies all the specified changes to the specified paths.

        This is a convenience method that wraps :meth:`notesdir.repos.base.Repo.change`
        """
        edits = []
        for path in paths:
            edits.extend(AddTagCmd(path, t.lower()) for t in add_tags)
            edits.extend(DelTagCmd(path, t.lower()) for t in del_tags)
            if title is not None:
                edits.append(SetTitleCmd(path, title))
            if created is not None:
                edits.append(SetCreatedCmd(path, created))
        self.repo.change(edits)
コード例 #5
0
ファイル: test_markdown.py プロジェクト: dendronhq/notesdir
def test_change_metadata_tags(fs):
    doc = """---
keywords:
- one
- two
...
text"""
    expected = """---
keywords:
- three
- two
...
text"""
    path = '/fakenotes/test.md'
    fs.create_file(path, contents=doc)
    acc = MarkdownAccessor(path)
    acc.edit(AddTagCmd(path, 'THREE'))
    acc.edit(DelTagCmd(path, 'ONE'))
    assert acc.save()
    assert Path(path).read_text() == expected
コード例 #6
0
ファイル: test_pdf.py プロジェクト: dendronhq/notesdir
def test_change(fs):
    path = str(Path(__file__).parent.joinpath('test.pdf'))
    fs.add_real_file(path, read_only=False)
    acc = PDFAccessor(path)
    acc.edit(SetTitleCmd(path, 'Why Donuts Are Great'))
    acc.edit(
        SetCreatedCmd(path,
                      datetime.fromisoformat('1999-02-04T06:08:10+00:00')))
    acc.edit(AddTagCmd(path, 'tag3'))
    acc.edit(DelTagCmd(path, 'tag2'))
    assert acc.save()
    with open(path, 'rb') as file:
        pdf = PdfFileReader(file)
        assert 'I like donuts' in pdf.getPage(0).extractText()
        # Make sure we didn't destroy preexisting metadata
        assert pdf.getDocumentInfo()['/Creator'] == 'Pages'
    info = PDFAccessor(path).info()
    assert info.title == 'Why Donuts Are Great'
    assert info.created == datetime.fromisoformat('1999-02-04T06:08:10+00:00')
    assert info.tags == {'tag1', 'tag3'}
コード例 #7
0
ファイル: base.py プロジェクト: dendronhq/notesdir
 def del_tag(self, path: str, tag: str) -> None:
     """Convenience method equivalent to calling change with one :class`notesdir.models.DelTagCmd`"""
     self.change([DelTagCmd(path, tag)])