⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wordwrap.py

📁 在 linux平台上的网页编程的模板
💻 PY
字号:
"""WordWrapping"""import os, sys, string, time, getoptimport redef WordWrap(text, cols=70, detect_paragraphs = 0, is_header = 0):  text =  string.replace(text,"\r\n", "\n") # remove CRLF  def nlrepl(matchobj):    if matchobj.group(1) != ' ' and matchobj.group(2) != ' ':      repl_with = ' '    else:      repl_with = ''    return matchobj.group(1) + repl_with + matchobj.group(2)  if detect_paragraphs:    text = re.sub("([^\n])\n([^\n])",nlrepl,text)  body = []  i = 0  j = 0  ltext = len(text)  while i<ltext:    if i+cols < ltext:      r = string.find(text, "\n", i, i+cols)      j = r      if r == -1:        j = string.rfind(text, " ", i, i+cols)        if j == -1:          r = string.find(text, "\n", i+cols)          if r == -1: r = ltext	  j = string.find(text, " ", i+cols)	  if j == -1: j = ltext          j = min(j, r)    else:      j = ltext    body.append(string.strip(text[i:j]))    i = j+1  if is_header:    body = string.join(body, "\n ")  else:    body = string.join(body, "\n")  return body

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -