Fork me on GitHub
#clojurescript
<
2020-06-19
>
dpsutton01:06:18

does anyone know if there's a relevant room for the mfikes esprit cljs boards?

mfikes02:06:54

@dpsutton I just made #esprit ... seems like a good idea to have such a thing 🙂

dpsutton02:06:11

i agree. thanks!

henryw37408:06:23

in advanced-optmization browser builds, I always get var process={} this appears after foreign-libs and before my actual code. the variable is not actually referred to in any of the output of the builds. This is on recent versions of cljs - not sure about older versions. Anyone know what it's doing there? I mean I guess it has something to do with node, which has always provides process object. As you might guess it's causing a problem with a non-cljs library that must be using the presence of this to decide what platform it's on

thheller08:06:58

likely the :process-shim compileroption? I'm not sure what the default is, might be true?

henryw37409:06:17

exactly that! thanks very much.

Spaceman20:06:09

suppose I want to bold some text in a div:

[:div "This is some text and THIS should be bold."]
and I want "THIS" to be bold. Do I have to split the div, or can this be done within the string?

p-himik20:06:05

You can wrap "THIS" in a span within that div and style that span.

Spaceman22:06:14

how do I turn the html response of a clj-http.client/get request into hiccup?

Spaceman22:06:38

one uses hiccup.core/html to convert from hiccup to html

Spaceman22:06:44

how to do the opposite?

noisesmith22:06:32

I've used enlive ages ago for something similar - it did give me data structures from html, but I don't think it was hiccup

noisesmith22:06:49

if there's something that does do html->hiccup reliably I don't know of it

noisesmith22:06:58

yeah - it ha functions to extract data from html

Spaceman22:06:11

So long as it is parsable it will suit the need. Doesn't have to be huicup. how did the api work for converting an html string to a parsable data structure?

noisesmith22:06:14

the html-resource function, if I recall correctly

Spaceman22:06:13

This example there:

(-> "" URL. html-resource 
  (select [:body :img]) first :attrs :src) 
gives nil

noisesmith22:06:20

perhaps the structure of the page has changed - if you just stop at html-resource, what does that look like?

Spaceman22:06:07

Yeah that returns

({:type :dtd, :data ["HTML" "-//IETF//DTD HTML 2.0//EN" ""]}
 {:tag :html,
  :attrs nil,
  :content
  ({:tag :head,
    :attrs nil,
    :content ("\n" {:tag :title, :attrs nil, :content ("302 Found")} "\n")}
   {:tag :body,
    :attrs nil,
    :content
    ("\n"
     {:tag :h1, :attrs nil, :content ("Found")}
     "\n"
     {:tag :p,
      :attrs nil,
      :content
      ("The document has moved "
       {:tag :a,
        :attrs {:href ""},
        :content ("here")}
       ".")}
     "\n"
     {:tag :hr, :attrs nil, :content nil}
     "\n"
     {:tag :address,
      :attrs nil,
      :content
      ("Apache/2.4.38 (Debian) Server at  Port 80")}
     "\n")}
   "\n")})
but on another url I tried, this error is thrown:
Execution error (UnknownServiceException) at java.net.URLConnection/getContentHandler (URLConnection.java:1241).
no content-type

        URLConnection.java: 1241  java.net.URLConnection/getContentHandler
        URLConnection.java:  740  java.net.URLConnection/getContent
                  URL.java: 1081  java.net.URL/getContent
           enlive_html.clj:  115  net.cgrand.enlive-html/eval44675/fn
              MultiFn.java:  234  clojure.lang.MultiFn/invoke
           enlive_html.clj:   69  net.cgrand.enlive-html/html-resource
           enlive_html.clj:   66  net.cgrand.enlive-html/html-resource
                      REPL:  115  user/eval45429
                      REPL:  115  user/eval45429
             Compiler.java: 7177  clojure.lang.Compiler/eval
             Compiler.java: 7132  clojure.lang.Compiler/eval
                  core.clj: 3214  clojure.core/eval
                  core.clj: 3210  clojure.core/eval
    interruptible_eval.clj:   91  nrepl.middleware.interruptible-eval/evaluate/fn
                  main.clj:  437  clojure.main/repl/read-eval-print/fn
                  main.clj:  437  clojure.main/repl/read-eval-print
                  main.clj:  458  clojure.main/repl/fn
                  main.clj:  458  clojure.main/repl
                  main.clj:  368  clojure.main/repl
               RestFn.java:  137  clojure.lang.RestFn/applyTo
                  core.clj:  665  clojure.core/apply
                  core.clj:  660  clojure.core/apply
                regrow.clj:   18  refactor-nrepl.ns.slam.hound.regrow/wrap-clojure-repl/fn
               RestFn.java: 1523  clojure.lang.RestFn/invoke
    interruptible_eval.clj:   84  nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj:   56  nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj:  155  nrepl.middleware.interruptible-eval/interruptible-eval/fn/fn
                  AFn.java:   22  clojure.lang.AFn/run
               session.clj:  190  nrepl.middleware.session/session-exec/main-loop/fn
               session.clj:  189  nrepl.middleware.session/session-exec/main-loop
                  AFn.java:   22  clojure.lang.AFn/run
               Thread.java:  748  java.lang.Thread/run

Spaceman22:06:19

how to fix the no content-type error?

noisesmith22:06:07

that's odd - must be the kind of thing browsers work around automatically...

dpsutton22:06:19

i think i remember looking at this once. its not super fun to parse a string as opposed to a resource based thing. either file uri or net uri

dpsutton22:06:39

it really wants to get something from somewhere

Spaceman22:06:11

In this particular case, there seems to be no api, so the html page must be fetched and parsed to extract the data

Spaceman22:06:20

@dpsutton are there alternatives to enlive for parsing html?

dpsutton22:06:42

i'm gonna google clj parse html to hiccup.

dpsutton22:06:37

seems like a jumping off point. but this seems like lots of jvm talk in the clojurescript channel

dpsutton23:06:00

(and not saying we shouldn't talk about it here, just worried that after a while down this rabbit hole these jvm based solutions won't fit your needs)