Skip to content

tom-clik/coldsoup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Coldsoup

CFML wrapper for JSoup.

Introduction

Working with JSoup in CFML often requires JavaCasting variables and quite cumbersome syntax. This component provides some simpler CFML methods.

Important Note

JSOUP has become incredibly popular and many other Java Libraries now bundle it, including the ever popular Flexmark. To ensure we load the library we want, we have to use the OSGI system in Lucee. This is very simple, but we need to know the path to the JSOUP Jar. In many ways this is better than loading through the class path.

Usage

  1. Instantiate the component as a singleton in a shared scope, e.g. application

    application.coldsoup = new coldSoup(pathtoJAR);
  2. Call static methods as required, e.g.

    myDoc = application.coldsoup.parse(html);
  3. Return type from parse() is a Jsoup Document.

    These can be searched with select(selector) where selector is a JQuery-like selector, e.g. p.class. The return value is sufficiently like a CF array to be used as one. Each element is a Jsoup Node. Modern versions of Jsoup should return an empty array if none are found. If you get null values, upgrade.

Examples

Parse html into a document for searching/updating

doc = coldSoup.parse(htmlDocument);
headings = doc.select("h2");
for (heading in headings) {...}

Return cleaned html

html = coldSoup.clean(html="<script>bad code</script> text", whitelist="basic" );

create JSoup node without having to JavaCast everything.

node = coldSoup.createNode("h2","my heading");

For further examples, see samples.

About

CFML Wrapper for Jsoup

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •