{"id":15562017,"url":"https://github.com/pobing/truncate_html_chinese","last_synced_at":"2025-03-29T04:43:48.149Z","repository":{"id":59158107,"uuid":"9740374","full_name":"pobing/truncate_html_chinese","owner":"pobing","description":null,"archived":false,"fork":false,"pushed_at":"2013-04-29T03:29:47.000Z","size":124,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-04T09:06:53.533Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pobing.png","metadata":{"files":{"readme":"README.md","changelog":"History.txt","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-04-29T03:26:32.000Z","updated_at":"2013-12-15T12:40:21.000Z","dependencies_parsed_at":"2022-09-13T20:11:17.086Z","dependency_job_id":null,"html_url":"https://github.com/pobing/truncate_html_chinese","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pobing%2Ftruncate_html_chinese","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pobing%2Ftruncate_html_chinese/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pobing%2Ftruncate_html_chinese/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pobing%2Ftruncate_html_chinese/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pobing","download_url":"https://codeload.github.com/pobing/truncate_html_chinese/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246140541,"owners_count":20729797,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-02T16:11:00.373Z","updated_at":"2025-03-29T04:43:48.110Z","avatar_url":"https://github.com/pobing.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"TruncateHtml\n============\n\n[![Build Status](https://secure.travis-ci.org/hgmnz/truncate_html.png?branch=master)](http://travis-ci.org/hgmnz/truncate_html)\n[![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/hgmnz/truncate_html)\n\ntruncate_html cuts off a string of HTML and takes care of closing any lingering open tags. There are many ways to solve this. This library does not have any dependencies, and [parses HTML using regular expressions](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454).\n\nIt can be used with or without Rails.\n\nExample\n-------\n\n```ruby\nsome_html = '\u003cul\u003e\u003cli\u003e\u003ca href=\"http://whatever\"\u003eThis is a link\u003c/a\u003e\u003c/li\u003e\u003c/ul\u003e'\ntruncate_html(some_html, :length =\u003e 15, :omission =\u003e '...(continued)')\n  =\u003e \u003cul\u003e\u003cli\u003e\u003ca href=\"http://whatever\"\u003eThis...(continued)\u003c/a\u003e\u003c/li\u003e\u003c/ul\u003e\n```\n\nA few notes:\n\n* By default, it will truncate on word boundary.\n  To truncate the HTML string strictly at the specified length, pass in the `:word_boundary =\u003e false` option.\n* If the input HTML is nil, it will return an empty string.\n* The omission text's length does count toward the resulting string's length.\n* `\u003cscript\u003e` tags will pass right through - they will not count toward the resulting string's length, or be truncated.\n\n* The default options are:\n  * `:length`: 100\n  * `:omission`: '...'\n  * `:word_boundary`: /\\S/\n\nYou may also set global configuration options.\nFor example, place the following on application boot,\nsomething like `config/initializers/truncate_html.rb`\n\n```ruby\nTruncateHtml.configure do |config|\n  config.length        = 50\n  config.omission      = '...(continued)'\nend\n```\n\nIf you really want, you can even set a custom word boundary regexp.\nFor example, to truncate at the end of the nearest sentence:\n\n```ruby\nTruncateHtml.configure do |config|\n  config.word_boundary = /\\S[\\.\\?\\!]/\nend\n```\n\nYou can also truncate the html at a specific point not based on length but content.\nTo do that, place the `:break_token` in your source. This allows the truncation to be\ndata driven, breaking after a leading paragraph or sentence. If the\n`:break_token` is in your content before the specified :length, :length will be\nignored and the content truncated at :break_token\nIf the `:break_token` is in your content after the specified :length,\n`:break_token` will be ignored and the content truncated at :length\n\n```ruby\nTruncateHtml.configure do |config|\n  config.break_token = '\u003c!-- truncate --\u003e'\nend\n```\nInstallation\n------------\n\nThe latest gem version for the Rails 2.x series is 0.3.2.\nTo use truncate_html on a Rails 2 app, please install the 0.3.2 version:\n\n    gem install truncate_html -v 0.3.2\n\nFor Rails 3, use the latest truncate_html:\n\n    gem install truncate_html\n\nIssues or Suggestions\n---------------------\n\nFound an issue or have a suggestion? Please report it on [Github's issue tracker](http://github.com/hgmnz/truncate_html/issues).\n\nTesting\n-------\n\n    bundle\n    rake\n\nAll green? Go hack.\n\nCopyright (c) 2009 - 2010 Harold A. Giménez, released under the MIT license\n\nThanks to all the [contributors](https://github.com/hgmnz/truncate_html/contributors)!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpobing%2Ftruncate_html_chinese","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpobing%2Ftruncate_html_chinese","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpobing%2Ftruncate_html_chinese/lists"}