Source

wikdNode / scripts / joinPeriod.groovy

The branch 'default' does not exist.
// @CacheScriptContent(true)
// @ExecutionModes({ON_SINGLE_NODE})
import org.apache.commons.lang.StringUtils as SU
import org.freeplane.core.util.HtmlUtils as HU

def joinPlain(String mark) {
	node.text = SU.join(
			c.selecteds.collect { SU.trim(it.plainText) }.toArray(), mark
			)
	c.selecteds.tail().each { it.delete() }
}

def joinAll(String mark) {
	// core text
	def core, coreMarkup
	def cores = []
	def coreHtml = false
	def coreHtmlNode = false
	// note text
	def note, noteMarkup
	def notes = []
	def noteHtml = false
	def noteHtmlNode = false
	// details text
	def detail, detailMarkup
	def details = []
	def detailHtml = false
	def detailHtmlNode = false
	// all children
	def children = []
	// all icons
	def icons = []

	// classify
	c.selecteds.each { n ->
		// core text
		if (n.text != null ) {
			core = n.text
			coreHtmlNode = HU.isHtmlNode(core)
			cores.add(core)
			coreHtml = coreHtml || coreHtmlNode
		}
		// note text
		if (n.note != null) {
			note = n.noteText
			noteHtmlNode = HU.isHtmlNode(note)
			notes.add(note)
			noteHtml = noteHtml || noteHtmlNode
		}
		if (n.details != null) {
			// detail text
			detail = n.detailsText
			detailHtmlNode = HU.isHtmlNode(detail)
			details.add(detail)
			detailHtml = detailHtml || detailHtmlNode
		}
		// children
		if (!n.children.empty()) {
			children.addAll(n.children)
		}
		// icons
		if (n.icons != null) {
			icons.addAll(n.icons?.icons)
		}
	}

	def tmpMarkup, writer, body

	// core texts
	if (!cores.empty()) {
		// core texts with HTML
		if (coreHtml) {
			coreMarkup = new XmlParser().parseText('<html><body></body></html>')
			body = coreMarkup.body
			cores.each {
				tmpMarkup = new XmlParser().parseText(it)
				tmpMarkup.body.each { part ->
					body?.appendNode(part)
					body?.appendNode(mark)
				}
			}
			writer = new StringWriter()
			new XmlNodePrinter(new PrintWriter(writer)).print(coreMarkup)
			node.text = writer.toString()
			// core texts without
		} else {
			node.text = SU.join(cores.toArray(), mark)
		}
	}

	// notes
	if (!notes.empty()) {
		// notes with HTML
		if (noteHtml) {
			noteMarkup = new XmlParser().parseText('<html><body></body></html>')
			body = noteMarkup.body
			notes.each {
				tmpMarkup = new XmlParser().parseText(it)
				tmpMarkup.body.each { part ->
					body?.appendNode(part)
					body?.appendNode(mark)
				}
			}
			writer = new StringWriter()
			new XmlNodePrinter(new PrintWriter(writer)).print(noteMarkup)
			node.noteText = writer.toString()
			// notes without
		} else {
			node.noteText = SU.join(notes.toArray(), mark)
		}
	}

	// details
	if (!details.empty()) {
		// details with HTML
		if (detailHtml) {
			detailMarkup = new XmlParser().parseText('<html><body></body></html>')
			body = detailMarkup.body
			details.each {
				tmpMarkup = new XmlParser().parseText(it)
				tmpMarkup.body.each { part ->
					body?.appendNode(part)
					body?.appendNode(mark)
				}
			}
			writer = new StringWriter()
			new XmlNodePrinter(new PrintWriter(writer)).print(detailMarkup)
			node.detailsText = writer.toString()
			// details without
		} else {
			node.detailsText = SU.join(details.toArray(), mark)
		}
	}

	// icons
	if (!icons.empty()) {
		node.icons?.icons?.clear()
		icons.each { node.icons.add(it) }
	}
	// children
	if (!children.empty()) {
		children.each { node.appendChild(it) }
	}

	// cleanup
	c.selecteds.tail().each { it.delete() }

	// present
	c.select(node)
	c.centerOnNode(node)
}

def pick(String mark) {
	if (mark != null) {
		mark = mark ? mark : ''
		if (Boolean.parseBoolean(config.getProperty('wikd_plain_text'))) {
			joinPlain(mark)
		} else {
			joinAll(mark)
		}
	}
}
pick('. ')
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.