商标取代下划线?

时间:2016-08-02 22:25:41

标签: javascript underscore.js

我的HTML下划线模板中的代码实际上是打印出来的

 "<sup>&reg;</sup>" 
在页面上的

而不是商标替换(®)我想要下面的代码。我的代码出了什么问题?编辑:我想将designation.title和designation.description打印到页面,只需用®替换那里的(R)。

<%- designation.title.replace(/(®)/ig, "<sup>&reg;</sup>") %>
<%- designation.description.replace(/(®)/ig, "<sup>&reg;</sup>")%>

3 个答案:

答案 0 :(得分:2)

您使用的是自动转义为HTML的template function类型: - (BOOL)convertMovieToMP4:(NSString ) originalMovPath andStoragePath:(NSString ) compMovPath { NSURL *tmpSourceUrl = [NSURL fileURLWithPath:originalMovPath]; compMovPath = [compMovPath stringByReplacingOccurrencesOfString:[compMovPath pathExtension] withString:@"mp4"]; NSURL *tmpDestUrl = [NSURL fileURLWithPath:compMovPath]; AVURLAsset* videoAsset = [[AVURLAsset alloc]initWithURL:tmpSourceUrl options:nil]; AVMutableComposition* mixComposition = [AVMutableComposition composition]; AVMutableCompositionTrack *compositionVideoTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid]; AVAssetTrack *clipVideoTrack = [[videoAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0]; [compositionVideoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, videoAsset.duration) ofTrack:clipVideoTrack atTime:kCMTimeZero error:nil]; [compositionVideoTrack setPreferredTransform:[[[videoAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] preferredTransform]]; CGSize videoSize = [[[videoAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] naturalSize]; CATextLayer *titleLayer = [CATextLayer layer]; titleLayer.string = @"Ojatro"; titleLayer.font = (_bridge CFTypeRef Nullable)(@"Helvetica"); titleLayer.fontSize = videoSize.height / 8; titleLayer.shadowOpacity = 0.2; titleLayer.alignmentMode = kCAAlignmentCenter; titleLayer.bounds = CGRectMake(0, 0, videoSize.width, videoSize.height / 6); titleLayer.position=CGPointMake(videoSize.width/2, videoSize.height/2); CALayer *parentLayer = [CALayer layer]; CALayer *videoLayer = [CALayer layer]; parentLayer.frame = CGRectMake(0, 0, videoSize.width, videoSize.height); videoLayer.frame = CGRectMake(0, 0, videoSize.width, videoSize.height); [parentLayer addSublayer:videoLayer]; [parentLayer addSublayer:titleLayer]; AVMutableVideoComposition* videoComp = [AVMutableVideoComposition videoComposition]; videoComp.renderSize = videoSize; videoComp.frameDuration = CMTimeMake(1, 30); videoComp.animationTool = [AVVideoCompositionCoreAnimationTool videoCompositionCoreAnimationToolWithPostProcessingAsVideoLayer:videoLayer inLayer:parentLayer]; AVMutableVideoCompositionInstruction *instruction = [AVMutableVideoCompositionInstruction videoCompositionInstruction]; instruction.timeRange = CMTimeRangeMake(kCMTimeZero, [mixComposition duration]); AVAssetTrack *videoTrack = [[mixComposition tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0]; AVMutableVideoCompositionLayerInstruction* layerInstruction = [AVMutableVideoCompositionLayerInstruction videoCompositionLayerInstructionWithAssetTrack:videoTrack]; instruction.layerInstructions = [NSArray arrayWithObject:layerInstruction]; videoComp.instructions = [NSArray arrayWithObject: instruction]; AVAssetExportSession* _assetExport = [[AVAssetExportSession alloc] initWithAsset:mixComposition presetName:AVAssetExportPresetMediumQuality];//AVAssetExportPresetPasst _assetExport.videoComposition = videoComp; //NSString* videoName = @"mynewwatermarkedvideo.mov"; NSString *tmpDirPath = [compMovPath stringByReplacingOccurrencesOfString:[compMovPath lastPathComponent] withString:@""]; if ([Utility makeDirectoryAtPath:tmpDirPath]) { NSLog(@"Directory Created"); } //exportPath=[exportPath stringByAppendingString:videoName]; NSURL *exportUrl = tmpDestUrl; if ([[NSFileManager defaultManager] fileExistsAtPath:compMovPath]) { [[NSFileManager defaultManager] removeItemAtPath:compMovPath error:nil]; } _assetExport.outputURL = exportUrl; _assetExport.shouldOptimizeForNetworkUse = YES; _assetExport.outputFileType = AVFileTypeMPEG4; //[strRecordedFilename setString: exportPath]; [_assetExport exportAsynchronouslyWithCompletionHandler: ^(void ) { switch (_assetExport.status) { case AVAssetExportSessionStatusUnknown: NSLog(@"Export Status Unknown"); break; case AVAssetExportSessionStatusWaiting: NSLog(@"Export Waiting"); break; case AVAssetExportSessionStatusExporting: NSLog(@"Export Status"); break; case AVAssetExportSessionStatusCompleted: NSLog(@"Export Completed"); totalFilesCopied++; [self startProgressBar]; break; case AVAssetExportSessionStatusFailed: NSLog(@"Export failed"); break; case AVAssetExportSessionStatusCancelled: NSLog(@"Export canceled"); break; } } ]; return NO; } 而不是<%-。使用它将导致下划线转义所有内容,以便它可以按原样输出(输出而不被解释为HTML,因此<%变为<&lt;变为&

如果要输出原始HTML,只需将&amp;关闭-,但这可能不安全,具体取决于<%-的其余部分以及是否有任何需要转义的字符

答案 1 :(得分:1)

改为使用<%=

<%- escapes HTML, <%= does not.

答案 2 :(得分:0)

创建一个DOM元素并将其放入其中。在您的情况下,将el对象传递给方法,而不是字符串?

&#13;
&#13;
var output = document.getElementsByTagName('div')[0];
var output2 = document.getElementsByTagName('div')[1];
var el = document.createElement( 'div' );
el.innerHTML = "<sup>&reg;</sup>";

var content = document.createTextNode("<sup>&reg;</sup>");

output.appendChild(el);

// this does not work
output2.appendChild(content);
&#13;
<div></div>
<div></div>
&#13;
&#13;
&#13;