Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

-writeJavascriptWithSrc:encoding: method that tries to do the right w…

…ith regards charset
  • Loading branch information...
commit 3a9930c80529f320ef99f379cfcef0df5bdcc36f 1 parent 1d5ee5f
@mikeabdullah mikeabdullah authored
Showing with 13 additions and 0 deletions.
  1. +1 −0  KSHTMLWriter.h
  2. +12 −0 KSHTMLWriter.m
View
1  KSHTMLWriter.h
@@ -126,6 +126,7 @@ extern NSString *KSHTMLWriterDocTypeHTML_5;
#pragma mark Scripts
+- (void)writeJavascriptWithSrc:(NSString *)src encoding:(NSStringEncoding)encoding;
- (void)writeJavascriptWithSrc:(NSString *)src charset:(NSString *)charset;
- (void)writeJavascript:(NSString *)script useCDATA:(BOOL)useCDATA;
- (void)startJavascriptElementWithSrc:(NSString *)src; // src may be nil
View
12 KSHTMLWriter.m
@@ -246,6 +246,18 @@ - (void)writeLinkToStylesheet:(NSString *)href
#pragma mark Scripts
+- (void)writeJavascriptWithSrc:(NSString *)src encoding:(NSStringEncoding)encoding;
+{
+ // According to the HTML spec, charset only needs to be specified if the script is a different encoding to the document
+ NSString *charset = nil;
+ if (encoding != [self encoding])
+ {
+ charset = (NSString *)CFStringConvertEncodingToIANACharSetName(CFStringConvertNSStringEncodingToEncoding(encoding));
+ }
+
+ [self writeJavascriptWithSrc:src charset:charset];
+}
+
- (void)writeJavascriptWithSrc:(NSString *)src charset:(NSString *)charset;
{
NSParameterAssert(src);
Please sign in to comment.
Something went wrong with that request. Please try again.