No internet connection
  1. Home
  2. Support

Stripping HTML from embedded javascript

By @richinnz2019-02-27 00:50:05.402Z

Hi, I have some Javascript on my page that uses the Typeahead library. When using wp2static there's 1 line of code that is being slightly altered and causing issues.

The code in my HTML is this:

jQuery('#remote .typeahead').typeahead({
	hint: true,
	highlight: true,
	minLength: 3
}, {
	name: 'full_address',
	displayKey: 'full_address',
	limit: 50,
	source: addressSource.ttAdapter(),
	templates: {
		suggestion: function (stock) {
			let address = (stock['habitation_name'] ? stock['habitation_name'] + " " : '') + stock['full_address'];
			return '<a href="#" data-id="' + stock.address_id + '" data-samid="' + stock['plsam'] + '" data-label="' + address + '">' + address + '</a>';
		}
	}
});

wp2static is removing the '</a>' on the last line, resulting in this:

return '<a href="#" data-id="' + stock.address_id + '" data-samid="' + stock['plsam'] + '" data-label="' + address + '">' + address + '';

noting the '' at the end of line instead of '</a>' which causes display issues in the output.

Is there any way I can work around this?

Thanks,
Richard

  • 1 replies
  1. Leon Stafford @leonstafford2019-02-27 03:11:49.592Z

    Hi Richard,

    Thanks for using the plugin!

    This will be due to the HTML parsing that takes place on any HTML files. The easiest fix will likely be to move that JS into it's own file and include it from the HTML file. This way, the plugin will not try to modify the JS file except for any full WordPress site URLs it finds.

    Please let me know if that fixes it for you.

    Cheers,

    Leon