AdamNiederer / AdamNiederer/elquery

Optionally keep whitespace in elquery-read-string

Open
#8 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Emacs Lisp
Stars
49
Forks
6
PR merge metrics
No merged PRs in 30d

Description

Is it possible to implement `elquery-read-string` to optionally keep the whitespace when reading the string?

```
-(defun elquery-read-string (string)
+(defun elquery-read-string (string &optional keep-whitespace)
"Return the AST of the HTML string STRING as a plist."
(with-temp-buffer
(set-buffer-multibyte nil) ; ref debbugs.gnu.org/cgi/bugreport.cgi?bug=31427
(insert string)
(let ((tree (libxml-parse-html-region (point-min) (point-max))))
(thread-last tree
- (--tree-map (if (stringp it) (s-trim (s-collapse-whitespace it)) it))
+ (--tree-map (if (and (stringp it)
+ (not keep-whitespace))
+ (s-trim (s-collapse-whitespace it)) it))
(elquery--parse-libxml-tree nil)))))
```

My use case scenario is parsing a lyrics html page. With the current implementation and the whitespace stripped, the newlines are removed resulting in a big one-liner string. I'm left guessing where one line ends and another one begins.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.