Search in sources :

Example 1 with RequestMarkdown

use of com.meisolsson.githubsdk.model.request.RequestMarkdown in project PocketHub by pockethub.

the class MarkdownLoader method load.

@Override
public CharSequence load(Account account) {
    RequestMarkdown markdown = RequestMarkdown.builder().mode(RequestMarkdown.MODE_GFM).text(raw).context(repository != null ? String.format("%s/%s", repository.owner().login(), repository.name()) : null).build();
    String html = ServiceGenerator.createService(activity, MarkdownService.class).renderMarkdown(markdown).blockingGet();
    if (encode) {
        return HtmlUtils.encode(html, imageGetter);
    } else {
        return html;
    }
}
Also used : RequestMarkdown(com.meisolsson.githubsdk.model.request.RequestMarkdown)

Example 2 with RequestMarkdown

use of com.meisolsson.githubsdk.model.request.RequestMarkdown in project gh4a by slapperwan.

the class ReleaseInfoActivity method loadBody.

private void loadBody() {
    final Single<Optional<String>> htmlSingle;
    if (TextUtils.isEmpty(mRelease.body())) {
        htmlSingle = Single.just(Optional.absent());
    } else {
        MarkdownService service = ServiceFactory.get(MarkdownService.class, false);
        RequestMarkdown request = RequestMarkdown.builder().context(mRepoOwner + "/" + mRepoName).mode("gfm").text(mRelease.body()).build();
        htmlSingle = service.renderMarkdown(request).map(ApiHelpers::throwOnFailure).map(Optional::of);
    }
    mBodySubscription = htmlSingle.compose(makeLoaderSingle(ID_LOADER_BODY, false)).subscribe(this::fillNotes, this::handleLoadFailure);
}
Also used : RequestMarkdown(com.meisolsson.githubsdk.model.request.RequestMarkdown) Optional(com.gh4a.utils.Optional) ApiHelpers(com.gh4a.utils.ApiHelpers) MarkdownService(com.meisolsson.githubsdk.service.misc.MarkdownService)

Example 3 with RequestMarkdown

use of com.meisolsson.githubsdk.model.request.RequestMarkdown in project PocketHub by pockethub.

the class HttpImageGetter method bind.

/**
 * Bind text view to HTML string
 *
 * @param view
 * @param html
 * @param id
 * @return this image getter
 */
public HttpImageGetter bind(final TextView view, final String html, final Object id) {
    if (TextUtils.isEmpty(html)) {
        return hide(view);
    }
    CharSequence encoded = fullHtmlCache.get(id);
    if (encoded != null) {
        return show(view, encoded);
    }
    encoded = rawHtmlCache.get(id);
    if (encoded == null) {
        if (!html.matches("<[a-z][\\s\\S]*>")) {
            RequestMarkdown requestMarkdown = RequestMarkdown.builder().text(html).build();
            ServiceGenerator.createService(context, MarkdownService.class).renderMarkdown(requestMarkdown).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(data -> continueBind(view, data.body(), id), e -> continueBind(view, html, id));
        } else {
            return continueBind(view, html, id);
        }
    }
    return continueBind(view, html, id);
}
Also used : RequestMarkdown(com.meisolsson.githubsdk.model.request.RequestMarkdown)

Aggregations

RequestMarkdown (com.meisolsson.githubsdk.model.request.RequestMarkdown)3 ApiHelpers (com.gh4a.utils.ApiHelpers)1 Optional (com.gh4a.utils.Optional)1 MarkdownService (com.meisolsson.githubsdk.service.misc.MarkdownService)1