nicolasgoutaland / gonmarkupparser Goto Github PK
View Code? Open in Web Editor NEWEasily build NSAttributedString from XML/HTML like strings for iOS.
License: MIT License
Easily build NSAttributedString from XML/HTML like strings for iOS.
License: MIT License
"GONMarkupParagrap.m" is written with an "h" at the end and not "Paragrap"
Hi, i just wanted to tell you that 'Strong' Markup is missing, i already added on my copy of this Lib, but you should consider it for further releases.
Another question about extract attributes regexp in code below:
([^\\s=]+)\\s*=\\s*('(\\\\'|[^']*')|\"(\\\\\"|[^\"])*\")
why not is below:
([^\\s=]+)\\s*=\\s*('(\\\\'|[^'])*'|\"(\\\\\"|[^\"])*\")
In class GONMarkupImage.m (line 22), the screen scale is stored in a variable. The very next line, the scale is hardcoded to 2.
The fact that initial value of scale is never used is causing a compiler warning, but I would assume that the hardcoded scale of 2 was not intentional as scales of 1 and 3 are also possible (with 3 becoming more popular as newer devices are released).
The code crashes when attempting to parse the following string:
@"<br>><<body>This is expected string<font color=\">Color</xxxx></body><"
I know it is invalid, but it should recover gracefully.
Error thrown:
caught "NSRangeException", "*** -[__NSCFConstantString substringToIndex:]: Index 18446744073709551615 out of bounds; string length 0"
Hi,
I'm having trouble with your recent link support code. The demo doesn't appear to work on either of my test devices - An iOS 7 iPhone 5 and an iOS 8 iPhone 4S. The links are rendered but not selectable and the delegate is never called.
I've had slightly more luck porting the code into my own App - it seem to work on the iOS 8 device but the links are rendered but not selectable on my iOS 7 device.
Any ideas why that might be?
I can not find any API for iOS 7 and later, but the cocoapods said it is for iOS 7 and later.
Is it support for iOS 6?
Changing manually #import <NSString+Color.h> to #import "NSString+Color.h" solves the issue.
I have to find the height of below mention string.
<b><font color='#565E6F'>Apollo Munich - Dengue Care<\/font><\/b><br><font color='#565E6F'>  Sum Insured : <\/font><b><font color='#565E6F'>₹ 50 K<\/font><\/b><br><font color='#565E6F'>  Premium : <\/font><b><font color='#565E6F'><b><font color='#565E6F'>₹<\/font><\/b> 511<\/font><\/b><br><font color='#565E6F'>  Members : <\/font><b><font color='#565E6F'>All Members<\/font><\/b>
[!] Invalid Podfile
file: [!] The specification of link_with
in the Podfile is now unsupported, please use target blocks instead..
The demo needs an update to it's podfile
I try to parse <span class="keyword">
and <span class="string">
.
This is my setup:
[[GONMarkupParserManager sharedParser] addMarkup:[GONMarkupSimple simpleMarkup:@"<span class=\"string\">" style:@{ NSFontAttributeName: [UIFont fontWithName:@"Menlo-Regular" size:fontSize], NSForegroundColorAttributeName: [UIColor redColor] } mergingStrategy:GONMarkupSimpleMergingStrategyMergeAll]];
I've also tried:
[[GONMarkupParserManager sharedParser] addMarkup:[GONMarkupSimple simpleMarkup:@"span class=\"string\"" style:@{ NSFontAttributeName: [UIFont fontWithName:@"Menlo-Regular" size:fontSize], NSForegroundColorAttributeName: [UIColor redColor] } mergingStrategy:GONMarkupSimpleMergingStrategyMergeAll]];
In both cases, I receive MarkupParser : No markup found for tag . Of course, I can add span
as a tag, but I need to differentiate strings and keywords.
Do you have a solution for this problem?
Btw: Great parser! 🙌
Hi @nicolasgoutaland ,
I'm looking for a function to insert text on a UITextView.
for example:
textView.insert("<strong>house</strong>")
textView.insert("<blue>car</car>")
This way I'm adding text dynamically istead of converting the whole text.
There is a way to do that? I only saw .setMarkedUpText(String) function.
I'm looking for something like .insertMarkedUpText(String).
the following:
- (NSAttributedString *)computeFinalExtractedString:(NSString *)inputString
{
GONMarkup *currentMarker = [_markupsStack lastObject];
if (currentMarker && ![currentMarker isKindOfClass:[NSNull class]])
{
NSString *string = [currentMarker updatedContentString:inputString
context:_currentContext
attributes:[self attributesForCurrentTag]];
if ([string isKindOfClass:[NSString class]]) {
return [[NSAttributedString alloc] initWithString:string
attributes:[self currentConfiguration]];
}else if ([string isKindOfClass:[NSAttributedString class]]){
return (NSAttributedString*)string;
}
}
return [[NSAttributedString alloc] initWithString:inputString attributes:[self currentConfiguration]];
}
the following:
@implementation GONImageMarkup
+ (instancetype)imageMarkup
{
return [self markupForTag:@"image"];
}
- (id)updatedContentString:(NSString *)string context:(NSMutableDictionary *)context attributes:(NSDictionary *)dicAttributes
{
UIImage *image = [UIImage imageNamed:[dicAttributes objectForKey:@"src"]];
if (image)
{
// 添加表情
NSTextAttachment *attch = [[NSTextAttachment alloc] init];
// 表情图片
attch.image = image;
// 设置图片大小
attch.bounds = CGRectMake(0, 0, image.size.width/2, image.size.height/2);
NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:attch];
return string;
}
return string;
}
#pragma mark - Style
- (void)openingMarkupFound:(NSString *)tag configuration:(NSMutableDictionary *)configurationDictionary context:(NSMutableDictionary *)context attributes:(NSDictionary *)dicAttributes
{
}
@end
Hello, I am trying a following code but still I am getting<p>
in my label text
let parser = GONMarkupParser.defaultMarkupParser()
parser.replaceNewLineCharactersFromInputString = true
parser.attributedStringFromString(html)
Try to parse next string < br >Hello World!< /br > (without spaces)
Output is empty string.
How to support image from remote-service?
<img src="http://h.hiphotos.baidu.com/image/h%3D200/sign=e72c850a09f3d7ca13f63876c21fbe3c/a2cc7cd98d1001e9460fd63bbd0e7bec54e797d7.jpg" />
When html body is
`
Hello
I want to using this component in swift language.
How? ....
LLVM/Clang warnings when compiling due to methods that accept NSError** not returning a BOOL value to indicate if there was an error.
File with error: GONMarkupParser.m
Methods with error:
Don't mind creating a PR if requested.
I have one question about autocloing tag parsing flow control while I reading the source code recently.
In parseString:error:
method, to determine the tag is autoclosing, then parse it seperately.
Why not replacing the autoclosing tag with the opening and closing tag pair before call parseString:error:
method. If this, the parsing flow control will become more consistent.
Hi,
Is it possible to support, for example:
<custom size = 20> and <custom size = "20">
Thanks
Hi,
Is GONMarkupParser can render an html like this one?
<html>
<head>
<style>
h2 {
font-family: 'OpenSans';
font-size: 19;
}
p {
font-family: 'OpenSans';
font-size: 14;
}
u {
font-family: 'OpenSans';
font-size: 14;
text-decoration: 'underline';
}
em {
font-family: 'OpenSans-Italic';
font-size: 14;
}
code {
font-family: 'OpenSans-Light';
font-size: 14;
}
h3 {
font-family: 'OpenSans';
font-size: 16;
}
div {
font-family: 'OpenSans';
font-size: 14;
}
span {
font-family: 'OpenSans';
font-size: 14;
}
h1 {
font-family: 'OpenSans';
font-size: 21;
}
b {
font-family: 'OpenSans-Bold';
font-size: 14;
}
</style>
</head>
<body>
<h1>Titre 1</h1>
<h2>Titre 2</h2>
<h3>Titre 3</h3>
<p>
<strong>gras</strong><br/>
<em>italic</em><br/>
<u>underscore</u>
</p>
<p><code>ruby
require 'redcarpet'
markdown = Redcarpet.new("Hello World!")
puts markdown.to_html
</code></p>
<p>This is a text</p>
<p>An image</p>
<p>
<a href="http://www.houstonpettalk.com/wp-content/uploads/2009/04/grass.jpg"><img src="http://www.houstonpettalk.com/wp-content/uploads/2009/04/grass.jpg" height="156" width="218" alt="grass.jpg" /></a>
</p>
<p>A video</p>
<video height="150" width="218" controls>
<source src="http://www.quirksmode.org/html5/videos/big_buck_bunny.mp4" type="video/mp4"> Your browser does not support the video tag.
</video>
</body>
</html>
Hi,
I test your library, but I have a problem with this :
Title<small><right>Name</right>/small>
Alignment don't work.
Any idea?
Thanks
I have added this library, but I can' compile it as following error log.
/.../Pods/GONMarkupParser/Classes/GONMarkupColor.m:10:9: 'NSString+Color/NSString+Color.h' file not found
I'm using Cocoapods 1.0.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.