Skip to content

Add initial Markdown support - #29

Open
strzibny wants to merge 8 commits into
masterfrom
markdown
Open

Add initial Markdown support#29
strzibny wants to merge 8 commits into
masterfrom
markdown

Conversation

@strzibny

@strzibny strzibny commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

This is WIP change for Markdown support.

@strzibny

Copy link
Copy Markdown
Contributor Author

Maybe we should call this .md() instead of .markdown() to align with serpapi/serpapi-python#39

Comment thread lib/serpapi/client.rb Outdated
# @param [String|Symbol, nil] output response format using the SerpApi output parameter [optional]
# @return [String|Hash] raw HTML, Markdown, or JSON / Hash
def search_archive(search_id, format = :json, output: nil)
format = output.to_s.to_sym unless output.nil?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why separate format and output arguments?

@trusche

trusche commented Aug 18, 2026

Copy link
Copy Markdown
Member

Maybe we should call this .md() instead of .markdown() to align with serpapi/serpapi-python#39

Personally I prefer markdown() over md()

@strzibny

Copy link
Copy Markdown
Contributor Author

Thanks @trusche for having a look. You are right on search_archive, we should cleanly just pass the extension. I fixed it.

Personally I prefer markdown() over md()

Well, that's how I started as well :) However, consistency among our clients is more important I think (already in Python and PHP libs) and I think there is a tiny advantage of matching the extension.

@trusche

trusche commented Aug 18, 2026

Copy link
Copy Markdown
Member

Ruby and rails offer a lot of syntactic sugar, we could at least create an alias?

@strzibny

Copy link
Copy Markdown
Contributor Author

I was thinking about it, but on the other hand I want us to be direct in docs and want to send people to one method everywhere. So creating an alias just on its own doesn't feel that good to me.

json, html, md are all shortcuts/abbreviations and in that sense it just works in uniform. I think that in the end uniformity among the abbreviations and across the libraries is just more important. They also directly suggest the extension in their meaning.

Do you think it's still worth it?

@pulkitchowdry

Copy link
Copy Markdown

@strzibny Thanks for the efforts. Functionality wise everything looks good to me 👍

One minor thing I observed (not due to code changes as part of this PR) is that when I pass output: "md" or output: "html" as a parameter in my SerpApi params then my output response for search method is broken with JSON parse related errors (since we default decoder to json. For any other values, for example output: "markdown" we throw an error instead of a broken response. Should we also throw an error for this? maybe we can check under a new issue.

I feel it would be good to mention some sample code in our Readme doc. Something like below where we are differentiating the three,

# For JSON output
result_json     = serpapi_client.search

# For HTML output
result_html     = serpapi_client.html

# For Markdown output
result_md       = serpapi_client.md

Note - I observe that our python library supports output in params so maybe in the future we can also support it in Ruby.

@pulkitchowdry pulkitchowdry left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@strzibny

Copy link
Copy Markdown
Contributor Author

Thanks @pulkitchowdry, you are right, we should have already been choosing the right decoder for HTML. I included it in this change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants