Beispiel #1
0
 def wikifier(text):
   if "<html>" in text and "</html>" in text:
     return text
   else:
     text =re.sub("\<\<([^\>]*)\>\>","= !macroerror! =",text)
     text= wikitext_to_wikklyhtml(environ["nojs_base"], environ["nojs_path"], text)
     text = re.sub("= !macroerror! =","<a class='errorButton'>Error in macro - javascript is required!</a>",text)
     return text
Beispiel #2
0
def create_tiddler(tiddler_name,location,environ):
  store = environ['tiddlyweb.store']
  try:
    tiddler = store.get(Tiddler(tiddler_name,get_bag(tiddler_name,environ)))
    text = wikitext_to_wikklyhtml(environ["nojs_base"], environ["nojs_path"], tiddler.text)
  except NoTiddlerError:
    text = ""
  create_jinja_template_file("%s%s"%(location,tiddler_name),"%s"%(text))
Beispiel #3
0
 def _plain_textify_string(self, title):
     """
     Take a string that may be HTML and turn it
     into plain text by finding all the included
     text.
     """
     output = wikitext_to_wikklyhtml('', '', unicode(title))
     parser = html5lib.HTMLParser(
             tree=treebuilders.getTreeBuilder('beautifulsoup'))
     soup = parser.parse(output)
     title = soup.findAll(text=True)
     return ''.join(title).rstrip().lstrip()
 def _build_template(self,node,tiddler):
   logging.debug("building template nasty %s"%node.attributes)
   nodeValue = node.nodeValue
   environ = self.environ
   tiddler_mappings = self.tiddlers
   #logging.debug("value is %s"%nodeValue)
   try:
     tagName = node.tagName
     #logging.debug("tag name is %s"%tagName)
     result = u"<%s "%tagName
     for attribute in ["id","class","_macro","macro","title","action","method","name","href","src","type","value"]:
       try:
         name= attribute
         if name == 'macro':
           name = "_macro"
         value = node.attributes[attribute].value
         result += '%s="%s" '%(name,value.replace('"',"'"))
       except KeyError:
         pass
     result += ">"
     if nodeValue:
       result += nodeValue
     try:
       macro =node.attributes["macro"].value
       result += self._run_macro(macro,tiddler)
     except KeyError:
       pass
     try:
       include_tiddler =node.attributes["tiddler"].value
       tiddler = tiddler_mappings[include_tiddler]
       #wikify it
       self._dependencies.append(include_tiddler)
       logging.debug("no bag for some reason in wikitext build_template")
       included = wikitext_to_wikklyhtml(self.environ["tw_url_base"], self.environ["tw_url_path"], tiddler.text, environ,tiddler=tiddler,suffix_url=self.environ["tw_url_suffix"],bag=self.bag)
       result += included.replace("&lt;","<").replace("&gt;",">")
     except KeyError:
       pass
     children= node.childNodes
     try:
       elemid= node.attributes["id"].value
       if elemid == "tiddlerDisplay":
         result += self._include_default_tiddlers()
     except KeyError:
       elemid = False
     for child in children:
       result += self._build_template(child,tiddler)
     result += "</%s>"%tagName  
     return result
   except AttributeError:
     if nodeValue:
       return nodeValue
     else:
       return u""    
Beispiel #5
0
def _view_transform(context,value,vtype,params=[]):
  
  #value = value.encode("ascii","ignore")
  environ = context.environ

    
  named_args = get_named_args(params)
  logging.debug("got named args %s from %s"%(named_args,params))
  try:
    prefix = named_args["prefix"]
    prefix =_do_transclusion(prefix,context.tiddler)
  except KeyError:
    prefix = ""
  try:
    suffix =named_args["suffix"]
    suffix =_do_transclusion(suffix,context.tiddler)
  except KeyError:
    suffix = ""
  try:
    label = named_args["label"]
    label = _do_transclusion(label,context.tiddler)
  except KeyError:
    label = value
  #logging.debug("view_transform %s %s %s"%(value,vtype,params))
  if not vtype or vtype =='text':
    transformed = value.decode("utf-8")
    return transformed
  elif vtype == 'wikified':
    return value#wikitext_to_wikklyhtml(environ["tw_url_base"], environ["tw_url_path"], value, environ,tiddler=context.tiddler,suffix_url=link_suffix,bag=context.bag)
  elif vtype =='link':
    value = "[[%s]]"%value
    return wikitext_to_wikklyhtml(environ["tw_url_base"], environ["tw_url_path"], value, environ,tiddler=context.tiddler,suffix_url=environ["tw_url_suffix"],bag=context.bag)
  elif vtype=='date':
    YYYY = value[0:4]
    MM = value[4:6]
    DD = value[6:8]
    h = value[8:10]
    m = value[10:12]
    s = value[12:14]
    return "%s/%s/%s"%(DD,MM,YYYY)
    #return "%s/%s/%s %s:%s:%s"%(DD,MM,YYYY,h,m,s)
  elif vtype == 'linkexternal':
    return u'<a href="%s%s%s">%s</a>'%(prefix,value,suffix,label)
  else:
    logging.debug("unknown view type %s"%vtype)
    transformed = ""#"%s(%s)"%(vtype,value)
  
  #logging.debug("returning %s"%transformed)
  return transformed
Beispiel #6
0
    def _add_tiddler_to_feed(self, feed, tiddler,view_template=False):
        if tiddler.recipe:
            tiddler_link = 'recipes/%s/tiddlers/' % iri_to_uri(tiddler.recipe)
            bagobject = control.determine_tiddler_bag_from_recipe(self.store.get(Recipe(tiddler.recipe)), tiddler)
            bag = bagobject.name
        else:
            tiddler_link = 'bags/%s/tiddlers/%s' % iri_to_uri(tiddler.bag)
            bag = tiddler.bag
        tiddler_link +=iri_to_uri(urllib.quote(tiddler.title.encode('utf-8'), safe=''))
        item_title = tiddler.title
        if view_template:
          if bag in view_template:
            if "link" in view_template[bag]:
              tiddler_link = wikitext_to_wikklyhtml("/", "/", view_template[bag]["link"], self.environ,tiddler=tiddler)
              #tiddler_link = render_wikitext(view_template[bag]["link"],self.environ)
            if "title" in view_template[bag]:
              item_title = wikitext_to_wikklyhtml("/", "/", view_template[bag]["title"], self.environ,tiddler=tiddler)
        link = u'%s/%s' % \
                (self._server_url(), tiddler_link)

              
        if tiddler.type and tiddler.type != 'None':
            description = 'Binary Content'
        else:
            description = render_wikitext(tiddler, self.environ)

        
        
        feed.add_item(title=item_title,
                unique_id=self._tiddler_id(tiddler),
                link=link,
                categories=tiddler.tags,
                description=description,
                author_name=tiddler.modifier,
                pubdate=self._tiddler_datetime(tiddler.modified)
                )
Beispiel #7
0
def tiddler(context, *args):
  logging.debug("in tiddler macro")
  environ = context.environ
  if context.bag:
    bag = context.bag
    try:
      tiddler_requested = args[0].text
    except Exception:
      tiddler_requested = ""
    for tiddler in bag.list_tiddlers():
      if tiddler.title == tiddler_requested:
        
        text = wikitext_to_wikklyhtml(environ["tw_url_base"], environ["tw_url_path"], tiddler.text, environ,tiddler=context.tiddler,suffix_url=environ["tw_url_suffix"],bag=context.bag)
        #text = text.replace("&lt;","<").replace("&gt;",">")
        return text
    return "no tiddler with name %s"%tiddler_requested
  else:
    return "no bag"
 def _run_macro(self,macrotext,tiddler):
   environ = self.environ
   bag = self.bag
   logging.debug("no bag for some reason in wikitext run macro %s"%bag)
   text = wikitext_to_wikklyhtml(environ["tw_url_base"], environ["tw_url_path"], "<<%s>>"%macrotext , environ,tiddler=tiddler,suffix_url=environ["tw_url_suffix"],bag=bag)
   return text.replace("&lt;","<").replace("&gt;",">")