Пример #1
0
 def test_tagsAtStart(self):
     """ make sure a tag at the start of a line isn't confused 
     with a heading 
     """
     s = "#monster #cat"
     h, ts = mark.render(s)
     dpr("----- h: -----\n%s\n-----end", h)
     self.checkTags(h, ts, ["cat", "monster"])
     self.assertFalse("[" in h, "html doesn't contain '['")
     self.assertFalse("]" in h, "html doesn't contain ']'")
Пример #2
0
    def test_tagsUnderline(self):
        """ tags that replace a character with '_' """
        s = """\
[#a monster]
#a_nother
#xxx-yyy
"""
        h, ts = mark.render(s)
        dpr("----- h: -----\n%s\n-----end", h)
        self.checkTags(h, ts, ["a_monster", "a_nother", "xxx_yyy"])
Пример #3
0
def getTitle(pan: str) -> str:
    """ get the title of an article
    @param pan = full pathname to the article
    """
    src = open(pan).read()
    lines = src.split("\n")
    if len(lines) == 0: return ""
    t = mark.render(lines[0].strip(" #"))
    if t.startswith("<p>"): t = t[3:]
    if t.endswith("</p>"): t = t[:-4]
    return t
Пример #4
0
def getArticleBody(art: str):
    """ given an article name, return the body of the article.
    @return::(str,str) = title,html
    """
    articlePan = butil.join(ARTICLE_DIR, art + ".md")
    #prvars()
    if butil.fileExists(articlePan):
        src = open(articlePan).read()
        contents = mark.render(src)
        return art, contents
    else:
        h = form("<p>({art} does not exist)</p>\n", art=art)
        return (pathName, h)
Пример #5
0
    def test_headings(self):
        s = """\
# should be h1 heading

## this is h2

### and h3
"""
        h, ts = mark.render(s)
        dpr("----- h: -----\n%s\n-----end", h)
        self.checkTags(h, ts, [])
        self.checkHeading(h, "should be h1 heading", "h1")
        self.checkHeading(h, "this is h2", "h2")
        self.checkHeading(h, "and h3", "h3")
Пример #6
0
def editMess(id):
    """ Edit an existing message """
    m = models.Message.getDoc(id)
    
    mf = MessageForm(message=m.source)
    if request.method=='POST':
        mf = mf.populateFromRequest(request)
        previewH, tags = mark.render(mf.message)
        
        m.source = mf.message
        m.html = previewH
        m.tags = tags
        m.editedAt = BzDateTime.now()
        m.save()
    #//if    
        
    tem = jinjaEnv.get_template("editMess.html")
    h = tem.render(
        m = m,
        id = id,
        ms = m.viewH(),
        mf = mf,
    )
    return h
Пример #7
0
def messRep(id=None):
    if id:
        isReply = True
        m = models.Message.getDoc(id)
        mh = m.viewH()
    else:
        isReply = False
        m = None
        mh = ""
    hasPreview = False
    previewH = ""
    tags = None

    mf = MessageForm()
    if request.method == 'POST':
        mf = mf.populateFromRequest(request)

        messRepButton = request.form['messRepButton']
        dpr("messRepButton=%r", messRepButton)
        if mf.isValid():
            if messRepButton == 'preview':
                #>>>>> preview message
                previewH, tags = mark.render(mf.message)
                hasPreview = True
            else:
                #>>>>> create message
                dpr("create new message")
                previewH, tags = mark.render(mf.message)
                newM = models.Message(source=mf.message,
                                      html=previewH,
                                      tags=tags,
                                      author_id=permission.currentUserName())
                if isReply:
                    newM.replyTo_id = id
                newM.save()
                models.notifyTags(tags)
                dpr("newM=%r", newM)
                dpr("tags=%r", tags)
                u = "/mess/" + newM.id()
                dpr("u=%r", u)
                if isReply:
                    al = models.Alert(user_id=m.author_id,
                                      alertType='reply',
                                      message_id=m._id,
                                      doer_id=newM.author_id,
                                      reply_id=newM._id)
                    al.save()
                return redirect(u, code=303)
        #//if valid
    #//if POST

    tem = jinjaEnv.get_template("messRep.html")
    h = tem.render(id=id,
                   isReply=isReply,
                   m=m,
                   mh=mh,
                   mf=mf,
                   msg="",
                   hasPreview=hasPreview,
                   previewH=previewH,
                   tagsH=htmlEsc(repr(tags)))
    return h
Пример #8
0
 def preSave(self):
     """ before saving, create the bioHtml """
     self.bioHtml, _ = mark.render(self.bio)
Пример #9
0
 def preSave(self):
     """ before saving, render the source into html """
     self.html, _ = mark.render(self.source, wikiExt=True)
Пример #10
0
 def test_tags(self):
     s = "some text #with #tags and #more #tags"
     h, ts = mark.render(s)
     dpr("----- h: -----\n%s\n-----end", h)
     self.checkTags(h, ts, ["more", "tags", "with"])
Пример #11
0
 def test_normal(self):
     s = "some text here"
     h, ts = mark.render(s)
     dpr("----- h: -----\n%s\n-----end", h)
     self.assertTrue("some text here" in h)
     self.checkTags(h, ts, [])